[LCP]#defines to know Endianness
Jack Lloyd
lloyd at acm.jhu.edu
Thu Jul 1 21:50:01 UTC 2004
I've found it's easier to just write the code so it works on either endianness
than deal with essentially two seperate codebases, one for big endian and one
for little endian. Also, this way you can support middle-endian machines. Which
probably hasn't been a concern for 30 years or so, but hey, why not? More
practically, you won't have to test your code on both little endian and big
endian systems just to make sure nothing has messed up. It's easy to let one or
the other (most likely big endian, as the whole worlds an x86 these days) rot.
If you have a case where this is impossible, I would like to see it. I've never
encountered a problem where you actually needed to know the CPU endianness to
get the job done.
And BTW, neither ISO C nor (I think) POSIX says anything about endianness. Your
best bet for that is BYTE_ORDER, which may or may not exist on the platforms
you want. It kind of depends what you mean by portable. Windows and Unix?
Windows, Unix, VMS, Symbian, OS/400, and OS/390? Or ... ?
-J
On Thu, Jul 01, 2004 at 12:38:17PM +0530, John Navil Joseph wrote:
> Hi,
>
> Is there any predefined macros (#defines like __cplusplus) that the
> compiler defines so as to know the endianess of the machine that the
> compiled code is to run on?
>
> I want to make my code portable, something like this..
>
> #ifdef __BIG_ENDIAN
> ...
> ...
> #else
> ...
> ...
> #endif
>
> TIA,
> John
> _______________________________________________
> This is the Linux C Programming List
> : http://lists.linux.org.au/listinfo/linuxcprogramming List
More information about the linuxCprogramming
mailing list