Will the C++ compiler, VS2010, convert big-endian to little-endian data for use on x86 machines?
Asked
Active
Viewed 1,835 times
0
-
1the compiler doesn't care about *data*, that is *your* responsibility... – Nim Nov 22 '13 at 14:53
-
The compiler takes care of correct little-endian or big-endian memory layout of data structures, including compiling numeric constants in source code to a machine-specific encoding, but it has no way to know whether data coming from outside (files, network packets, etc.) is big-endian or little-endian, so it cannot perform any magical automated conversion behind the program's back. – Lorenzo Gatti Nov 22 '13 at 16:02
2 Answers
0
Endianess of data is not converted once the program has been compiled, and it depends on the compiler.
Compilers can be big-endian, little-endian or both (for platforms that can run in both little-endian and big-endian modes). The x86 platform, however, is only little-endian (see here)

Claudio
- 10,614
- 4
- 31
- 71
0
The compiler will not perform any automagic endianness conversions. The compiler when targeting x86 knows that the architecture is little endian. And so accordingly it emits appropriate data that is also little endian.
If you receive data that is big endian, and you need to operate on it in little endian form, then you need to take explicit steps to convert it.

David Heffernan
- 601,492
- 42
- 1,072
- 1,490