• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

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

  • Prev by Date: Can't get Xcode & Perforce to work
  • Next by Date: Re: How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined?
  • Previous by thread: How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined?
  • Next by thread: Re: How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined?
  • Index(es):
    • Date
    • Thread