• 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: Eric Albert <email@hidden>
  • Date: Tue, 15 Nov 2005 16:27:28 -0800

On Nov 15, 2005, at 4:01 PM, Dave Thorup wrote:

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).

Nope. __LITTLE_ENDIAN__ is defined and set to 1 if you're building for Intel, and __BIG_ENDIAN__ is defined and set to 1 if you're building for PowerPC. Neither is defined on the other architecture.


Also, since only one of them is defined would it be better to use #if as I did above or should I use #ifdef?

In general, I prefer #if to #ifdef just because that protects you if someone writes code like this:


#if __LITTLE_ENDIAN__
#define __BIG_ENDIAN__ 0
#endif


For what it's worth, we don't recommend using __LITTLE_ENDIAN__ or __BIG_ENDIAN__ except in very rare cases. Use the swapping functions in the system instead. They compile down to nothing when you don't need to swap and keep you from having two copies of your code.


-Eric

_______________________________________________
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


  • Follow-Ups:
    • Re: How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined?
      • From: "Sean McBride" <email@hidden>
    • Re: How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined?
      • From: Dave Thorup <email@hidden>
References: 
 >How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined? (From: Dave Thorup <email@hidden>)

  • Prev by Date: Re: How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined?
  • Next by Date: XCode 2.2, templates, overloads, Obj-C types
  • Previous by thread: Re: How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined?
  • Next by thread: Re: How are __LITTLE_ENDIAN__ and __BIG_ENDIAN__ defined?
  • Index(es):
    • Date
    • Thread