5

I would like to know, if the types that are larger than the native machine word, and that have compiler abstraction support, like int64_t on a 32 bits system, have any specification on the byte order in memory ? For example, on little endian machines, should we suppose that the memory layout is a full 64 bits swaped order ? Or it is free to be a middle-endian like the PDP-11 ?

c.f. http://en.wikipedia.org/wiki/Endianness#Middle-endian

Because the __int64 (MS) or long long (gcc) were not standard before int64_t in C99, isn't it far fetched to suppose anything on the byte order of such types ?

Thanks

v.oddou
  • 6,476
  • 3
  • 32
  • 63
  • 1
    The C and C++ standard don't specify anything about byte order within integers. Check your compiler manual. – Fred Foo Nov 01 '13 at 09:57
  • @larsmans: In particular, they don't even guarantee consistency across or even within a type. Middle-endian is definitely allowed.. – MSalters Nov 01 '13 at 13:21

3 Answers3

1

Why would the standard want to specify on the byte order in memory of anything? In all cases this is up to the compier/architecture to freely decide. If you're interested in a specific architecture, just pop up your debugger and watch how a simple program behaves.

shoosh
  • 76,898
  • 55
  • 205
  • 325
  • Because for marshalling, it is reasonable to specify a little on this. The standard could say : "fondamental types are supposed to have consistent byte order layouts, according to the platform native support or memory page setting." So that you can expect a 64 bits to be layout the same than a 32 bits would be in the same page (or same machine for uniquely endianed machines). This would give serializers (for network or binary saves) a little bit more natural portability of their libraries. – v.oddou Nov 05 '13 at 00:26
0

C is a portable language and as such doesn't assume much about the actual representation of integer types. The standard even allows for padding bits sprinkled in between value bits ! For more information, see 6.2.6.2 Integer types.

diapir
  • 2,872
  • 1
  • 19
  • 26
0

I don't think C standard has any specification on the byte order. It's implementation dependent. In practice, I'd supposed that the endianess of int64_t follows the endianess of the architecture. So even in a 32bit program, the storage of int64_t in memory is just as if it were 64bit program. But it may requires two instructions to load/store the data as the register is 32bit.

tristan
  • 4,235
  • 2
  • 21
  • 45
  • Yes that is the point of the question :) It seems natural to think that way, but that's just a morale code that compiler writers will hold to while writing the "big number type" abstraction. And at the first contretemps, this consideration will snap to profit practicality. because no spec holds them to this. Hence my fear. – v.oddou Nov 05 '13 at 00:33