Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined?



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:
http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden

References: 
 >How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined? (From: Dave Thorup <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.