Timeline for Checking endianness at compile-time
Current License: CC BY-SA 3.0
9 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 23, 2017 at 12:40 | history | edited | CommunityBot |
replaced http://stackoverflow.com/ with https://stackoverflow.com/
|
|
Jul 1, 2016 at 8:43 | comment | added | user109835 | -1. Using unions for type punning in C++ is undefined behavior. | |
May 6, 2016 at 19:44 | comment | added | scottbb | @200_success True, however any particular module of code running on a bi-endian machine is compiled for a specific endianness. The processor can't change its endianness in the middle of a binary, and expect that same binary to execute correctly henceforth. | |
Nov 15, 2015 at 10:36 | comment | added | Ruslan | Your union "standard way" has undefined behavior according to the Standard. | |
Mar 29, 2014 at 16:37 | comment | added | Apprentice Queue |
@icdae you're right; I think someone mentioned that the standard technically prevents setting a union with one field but accessing it with a different one. But many compilers allow it. In that Stack Overflow link, there is one answer that uses the idea of casting int to char which might work better (but you should try uint32_t instead of int ).
|
|
Mar 29, 2014 at 8:23 | comment | added | icdae | I originally tried a union but got errors from G++ for undefined behavior. After setting the data for one member, then trying to access the other, I'll get errors that prevent the code from compiling. I figured the current method would be a safe bet, but completely overlooked how the data would be accessed through an array. The problem is that using behavior defined by the standard seems to limit how byte-level data can be access during compilation. Neither casting to another data type or bit-leven operations seem to work. | |
Mar 29, 2014 at 8:05 | history | edited | Jamal | CC BY-SA 3.0 |
Used better markdown
|
Mar 29, 2014 at 8:05 | comment | added | 200_success | Some processors can run in either big- or little-endian mode, leaving the choice up to the operating system. However, Windows will probably only ever run in little-endian mode. | |
Mar 29, 2014 at 7:57 | history | answered | Apprentice Queue | CC BY-SA 3.0 |