Re: Robust detection of endianness at compile time.

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

 



Lee Rhodes writes:
 > This issue started in a previous thread, but I have studied it a bit more
 > and decided to create another thread with a more focused title.  Hopefully,
 > there is an expert in the readers of this forum that can explain the whys.
 > 
 > There doesn't appear to be a simple and robust (i.e., cross-platform) way of
 > determining the endianness of the underlying platform at compile-time.

Yes, there is.  

Endianness, like hundreds of other environment quersies needed at
compile time, is handled by GNU Autoconf.  There's nothing special
about endianness: it's just another property of the environment you're
compiling for.

The macro you need is here:

? Macro: AC_C_BIGENDIAN ([action-if-true], [action-if-false], [action-if-unknown])

    If words are stored with the most significant byte first (like
    Motorola and SPARC CPUs), execute action-if-true. If words are
    stored with the least significant byte first (like Intel and VAX
    CPUs), execute action-if-false.

    This macro runs a test-case if endianness cannot be determined
    from the system header files. When cross-compiling, the test-case
    is not run but grep'ed for some magic values. action-if-unknown is
    executed if the latter case fails to determine the byte sex of the
    host system.

    The default for action-if-true is to define `WORDS_BIGENDIAN'. The
    default for action-if-false is to do nothing. And finally, the
    default for action-if-unknown is to abort configure and tell the
    installer which variable he should preset to bypass this test.

 > 5.  Where is the documentation on how one should write cross-platform code
 > wrt endianess using GCC?

http://www.gnu.org/software/autoconf/manual/autoconf.html

Andrew.

[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