RE: Where to find documentation on pre-defined macros

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks Brian and David,

Sounds like #include <endian.h> and testing for either __LITTLE_ENDIAN or
__BIG_ENDIAN is the way to go.  

The code I was studying tested for "__BIG_ENDIAN__" with no relevant
#includes...  Although this string might exist it seems a little flaky to
me.

Lee.




 

-----Original Message-----
From: David Daney [mailto:ddaney@xxxxxxxxxx] 
Sent: Wednesday, July 25, 2007 4:27 PM
To: gcc-help@xxxxxxxxxxx
Cc: Lee Rhodes
Subject: Re: Where to find documentation on pre-defined macros

Brian Dessent wrote:
> Lee Rhodes wrote:
> 
>>   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)?
> 
> Autoconf has the AC_C_BIGENDIAN macro that will determine the 
> endian-ness of the target at configure time.

And #include <endian.h> defines __BYTE_ORDER, __LITTLE_ENDIAN, and
__BIG_ENDIAN which can be tested at compile time.

You can also use htons/ntohs and ntonl/ntohl and they take care of it for
you.

David Daney



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux