How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined?
How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined?
- Subject: How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined?
- From: Dave Thorup <email@hidden>
- Date: Tue, 15 Nov 2005 19:01:39 -0500
I've been working on creating Universal Binaries and I've been using
the following where needed:
#if __LITTLE_ENDIAN__
// do little endian stuff
#else
// do big endian stuff
#endif
Most of this code is cross-platform C++ that is built for both
Windows and Mac OS X. Since neither of these macros are defined by
the VisualStudio compiler I need to come up with consistent
definitions to be used on the Windows side. It was my initial
understanding that both __LITTLE_ENDIAN__ and __BIG_ENDIAN__ are
defined no matter if you're compiling for x86 or PPC (one is defined
as 1 and the other 0). Given that, I thought I'd put the following
at the beginning of a file that uses the endian macros:
#if !defined( __BIG_ENDIAN__ ) || !defined( __LITTLE_ENDIAN__ )
# error Both __BIG_ENDIAN__ and __LITTLE_ENDIAN__ must be defined.
#endif
However after trying this I found that only one of the Macros is
defined. Is this behavior consistent for both GCC and CodeWarrior
(CodeWarrior should only worry about __BIG_ENDIAN__ being defined)?
If it is then I suppose I'll have to change my error warning to
something like:
#if !defined( __BIG_ENDIAN__ ) && !defined( __LITTLE_ENDIAN__ )
# error Either __BIG_ENDIAN__ or __LITTLE_ENDIAN__ must be defined.
#endif
Also, since only one of them is defined would it be better to use #if
as I did above or should I use #ifdef?
#ifdef __LITTLE_ENDIAN__
// do little endian stuff
#else
// do big endian stuff
#endif
Thanks!
_____________________________
Dave Thorup
Software Engineer
email@hidden
http://www.kuwan.net
HyperSpell - Check spelling in Mac OS X from any application.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden