Re: How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined?
Re: How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined?
- Subject: Re: How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined?
- From: Shawn Erickson <email@hidden>
- Date: Tue, 15 Nov 2005 16:26:05 -0800
On 11/15/05, Dave Thorup <email@hidden> wrote:
> However after trying this I found that only one of the Macros is
> defined.
Well likely only one should ever be defined at a time but to be safe
you can use #if to actually test the value not just if it is defined.
> #if !defined( __BIG_ENDIAN__ ) && !defined( __LITTLE_ENDIAN__ )
> # error Either __BIG_ENDIAN__ or __LITTLE_ENDIAN__ must be defined.
> #endif
This is correct error check in fact Apple's "CFByteOrder.h" does the
following...
#if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
#error Do not know the endianess of this architecture
#endif
Then it does the following to test for endianness...
CF_INLINE uint64_t CFSwapInt64HostToBig(uint64_t arg) {
#if defined(__BIG_ENDIAN__)
return arg;
#else
return CFSwapInt64(arg);
#endif
}
CF_INLINE uint16_t CFSwapInt16LittleToHost(uint16_t arg) {
#if defined(__LITTLE_ENDIAN__)
return arg;
#else
return CFSwapInt16(arg);
#endif
}
_______________________________________________
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