Thanks Brian, I find it curious that in the GCC source the only place I find a definition of "__LITTLE_ENDIAN__" is in fixincludes/inclhack.def and in fixincl.x. Which kind of implies that it is a "hack" :-) Nonetheless, if I had to write low-level code that depended on ENDIANess, what is the most robust/platform-independent way to make that determination (and not pay run-time execution costs)? Lee. -----Original Message----- From: Brian Dessent [mailto:brian@xxxxxxxxxxx] Sent: Wednesday, July 25, 2007 2:42 PM To: Lee Rhodes Cc: gcc-help@xxxxxxxxxxx Subject: Re: Where to find documentation on pre-defined macros Lee Rhodes wrote: > Apparently, GCC predefines some macro variables such as > __LITTLE_ENDIAN__ and __BIG_ENDIAN__ based on the current underlying > architecture, however, I only deduce this from studying code that > depends on them. I cannot seem to find any mention of these macros in the "Using the GNU Compiler Collection" > (4.2.0); no mention in Bjarne's "C++ Programming Language, 3rd ed."; > no mention in Josuttis's "C++ Standard Library". So where is the > list/documentation of all predefined macros the GCC provides? It's likely that this is target-dependent, i.e. it is defined not by any language standard but by the behavior of the vendor system compiler and/or platform specification documents, and gcc is just following that spec. $ find gcc/config -name \*.h | xargs egrep 'builtin_define.*_ENDIAN' gcc/config/i386/darwin.h: builtin_define ("__LITTLE_ENDIAN__"); \ gcc/config/i386/lynx.h: builtin_define ("__LITTLE_ENDIAN__"); \ gcc/config/ia64/ia64.h: builtin_define("__BIG_ENDIAN__"); \ gcc/config/m32r/m32r.h: builtin_define (TARGET_BIG_ENDIAN \ gcc/config/rs6000/lynx.h: builtin_define ("__BIG_ENDIAN__"); \ gcc/config/rs6000/netbsd.h: builtin_define ("__BIG_ENDIAN__"); \ gcc/config/rs6000/netbsd.h: builtin_define ("__LITTLE_ENDIAN__"); \ gcc/config/rs6000/rs6000.h: builtin_define ("__BIG_ENDIAN__"); \ gcc/config/rs6000/rs6000.h: builtin_define ("_BIG_ENDIAN"); \ gcc/config/rs6000/rs6000.h: builtin_define ("__LITTLE_ENDIAN__"); \ gcc/config/rs6000/rs6000.h: builtin_define ("_LITTLE_ENDIAN"); \ gcc/config/sh/sh.h: builtin_define (TARGET_LITTLE_ENDIAN \ gcc/config/xtensa/xtensa.h: builtin_define (TARGET_BIG_ENDIAN ? "__XTENSA_EB__" : "__XTENSA_EL__"); \ So, that's maybe eight out of however many various platforms gcc supports (25? 50? 100?) where these are defined... And notably x86 linux is not on that list: $ gcc -dM -E - </dev/null |grep -iq endian || echo "Not defined" Not defined >From a documentation standpoint it's nearly impossible for gcc to >emumerate platform-specific details like this in the manual because either you have to fork the manual into a hundred different variants, or you have to resort to big long lists, and in either case it's hard to maintain so it would tend to get out of sync. Note also that there is also the whole libc factor, in that e.g. glibc provides an endian.h. Brian