Xcode preprocessor defines

Does anyone know of a list of the automatic preprocessor #defines that xcode gives you?

I'm building a universal binary that needs some code to distinguish between ppc and i386. In metrowerks, #if __powerc does this, but it doesn't seem to work in Xcode...

thanks

Mac Mini, Mac OS X (10.4.9)

Posted on Dec 17, 2007 2:19 PM

Reply
6 replies

Dec 17, 2007 3:27 PM in response to Brian Postow

Okay so you have several macros :
_ppc_ = PPC 32 bits
_ppc64_ = PPC 64 bits
_i386_ = Intel 32 bits and/or 64 bits
_x86_64_ = Intel 64 bits

You also have interesting macros like :

_LP64_ = PPC and Intel 64 bits
NS BUILD_32_LIKE64 = Leopard only, it allows you to use simplification available in Leopard, for example, with Cocoa, you would have NSPoint, NSSize and NSRect and in Core Graphics framework you would have CGPoint, CGSize and CGRect, this macro allows you to make these types compatible : NSPoint = CGPoint, NSSize = CGSize and NSRect = CGRect.

And also you have the availability macros defined in AvailabilityMacros.h.

Dec 18, 2007 7:01 AM in response to etresoft

Oh, clearly I don't want them either. however, they're sort of unavoidable... at least temporarily.

I've got a couple of places with old PPC assembler. Also, the code historically uses old style resource files for some preference data. I'm in the process of turning that into text-files. However, the intel native version won't be able to read the resources (endian issues), so the PPC version reads the resource file and writes out the text file in preparation for eventually only using the intel version...

Also, there are parts of the code that were written during the Motoral - PPC change over, so there are some chunks of code that are protected there too. I'll have to figure out which of those are simply "not Motorola" and which are "PPC" but I'm sure that there are some of each.

Dec 18, 2007 7:19 AM in response to Brian Postow

Brian Postow wrote:
Oh, clearly I don't want them either. however, they're sort of unavoidable... at least temporarily.

I've got a couple of places with old PPC assembler.


Yes, that is pretty unavoidable. You'll want to handle that with the specific #define that matches that cpu, then do #else and do the rest not using assembly.

Also, the code historically uses old style resource files for some preference data. I'm in the process of turning that into text-files. However, the intel native version won't be able to read the resources (endian issues), so the PPC version reads the resource file and writes out the text file in preparation for eventually only using the intel version...


I don't like the sound of that. Are you sure the Intel can't read the resource data? If it is just regular resource data, it should be no problem. If you have binary structures inside that resource data, you can read it in and swap the bytes. What you do is read it into a buffer, knowing that the data has a certain endian-ness, and then use the platform independent byte-swapping routines to conver the data to whatever is appropriate for the currently running (PPC or Intel) system.

Any processor can handle any type of data, as long as it knows what the data is. Furthermore, your code can do that determination at runtime using platform independent routines, without #defines.

The ZIP file format, for example, uses both big and little-endian data at the same time.

All the #define macros or byte swapping routines you'll need are listed here.

Dec 18, 2007 8:22 AM in response to etresoft

etresoft wrote:
If you have binary structures inside that resource data, you can read it in and swap the bytes. What you do is read it into a buffer, knowing that the data has a certain endian-ness, and then use the platform independent byte-swapping routines to conver the data to whatever is appropriate for the currently running (PPC or Intel) system.



Exactly, we have binary data in resources. But we don't want to be byteswapping forever. So instead we're migrating to a text-based preference management system. The PPC version needs to be able to read the resource and write out the initial text files, and the intel version needs to be able to read the text files...

Basically, it's a temporary thing for the short term while we're migrating to a non-binary resource based system...


And is there a reason why there's a generic i386 define, but no generic PowerPC define? (I can use ! _i386_, or flip my #if #else structures, but I'm just curious)

thanks

Dec 18, 2007 9:28 AM in response to Brian Postow

Brian Postow wrote:
And is there a reason why there's a generic i386 define, but no generic PowerPC define? (I can use ! _i386_, or flip my #if #else structures, but I'm just curious)


I have no idea. I don't know the chip architectures that well. That is the problem with the #defines - to use them, you do need to know the architectures and why _ppc_ is not _ppc64_. That is why I would prefer the byte-swapping routines, even on PPC when, in theory, they aren't needed. Apple knows the difference between the chips and knows how to store data into them. You know how your data is formatted. Combine your knowledge of your data with Apple's knowledge of the architecture and you avoid #defines. Your code will also run on Intel. But, I think a text-based (hopefully XML) scheme would be much better. The problem would be if your code to read in these resources is already done and fairly complicated. In that case, it might just be better to check _ppc_ or _ppc64_ and test your code on both a G4 and G5. That link I posted may have more detail on the difference in those processors. I haven't read it myself.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Xcode preprocessor defines

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.