Home > front end >  Endianness for all c data types on Windows OS
Endianness for all c data types on Windows OS

Time:10-07

I am trying to document the different data types and how they are stored in memory in C. I know how many bytes each data type takes up but I would like to know how the endianness of every data type. This is specifically for Windows.

CodePudding user response:

The x86 and x86-64 processors are little-endian, and that's where you generally run Windows.

In other words, unless you're running Windows on Arm, all data on Windows is thus natively little-endian.

CodePudding user response:

I know how many bytes each data type takes up

That's impossible. C doesn't define sizes for any of its types. It only provides minimums. For example, an int need only be 16 bits in size, but it's common for it to be larger. This can vary between compiler and OS.

I would like to know how the endianness of every data type.

C doesn't define this either. It's going to depend on the hardware of the system. For example, x86 and x86_64 are little-endian. ARM is big-endian. And some old systems use byte orders that are different than both of these.

CodePudding user response:

Endianness is (usually) a function of the hardware, not the OS or the language, so all multi-byte types should have the same endianness.

Emphasis on should.

For x86 and x86_64 (on which Windows primarily runs), all multi-byte types are little-endian.

But there are always going to be some oddball platforms. The DEC VAX was little-endian except for floating-point types, which were stored in a combined big- and little-endian order. From Kapps & Stafford1:

The VAX was designed in part to be compatible with the PDP-11 computer. The PDP-11 is a 16-bit machine, and 32-bit and 64-bit floating point numbers were stored as sequences of 16-bit words with the most significant part coming first. This was unfortunate for the VAX, because the VAX almost universally places the least significant part first. Floating-point numbers are the main exception to this rule. As a consequence, when an F_floating number is stored in a longword, we have to reverse the first 16 bits with the last 16 bits.

IOW, each 16-bit word was big-endian (byte order 01), but the sequence of 16-bit words was little-endian, so the byte order of a 32-bit F_float was 2301.

As for type sizes...

C does not specify sizes for the "traditional" scalar types like int, long, float, double, etc. It specifies a minimum range of values that each type must be able to represent. A char must be able to represent all characters in the basic execution character set, meaning it must be at least 8 bits wide, but it may be wider (9-bit bytes and 36-bit words are a thing, or at least used to be). An int must be able to represent values in at least the range -32767..32767, meaning it must be at least 16 bits wide.


  1. Kapps, Charles A. and Robert L. Stafford, VAX Assembly Language and Architecture, Prindle, Weber & Schmidt 1985
  • Related