Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What definitions exist like __LP64__ and __arm64__ in Cocoa that differentiate platforms at compile time? Where or how are they defined?

With the introduction of arm64 as a standard architecture for the iphoneos platform it's necessary in some cases to implement compile-time conditions for code that is specific to the 64/32 architecture.

If you look at CoreGraphics/CGBase.h and how some popular open source projects are providing support for arm64 it's clear that you can check for the presence of the 64bit runtime like so:

#if defined(__LP64__) && __LP64__
...
#else
...
#endif

It's also possible to check specifically for arm64 (as opposed to just a 64bit runtime) as mentioned in this fix for erikdoe/ocmock

#ifdef __arm64__
...
#else
....
#endif

Is there a comprehensive list, or documentation for these kinds of definitions? Where or how are they defined?

like image 686
Jessedc Avatar asked Dec 09 '13 02:12

Jessedc


2 Answers

Those macros are not specific to Cocoa, they are specific to CLANG, and they can be listed on the command line with:

clang -dM -E -x c /dev/null

Different CLANG versions ship with varying amounts of feature flags which can get turned on and off at configuration time or depending on which platform and OS the compiler is running on. A fairly comprehensive list can be found in their testing headers with variants for each supported system also scattered around in the testing directory. Documentation for each depends on whether the flag is specific to CLANG, or defined in one of the standard libraries it links against (for example __llvm__ is defined by CLANG, but __WCHAR_WIDTH__ is defined by LibC). There is really no comprehensive list with definitive documentation for this reason. Different platforms are allowed to do things slightly differently so long as they adhere to language specifications.

The majority of the interesting public Objective-C macros exist in Foundation near the bottom of Foundation/NSObjCRuntime.h.

like image 124
CodaFi Avatar answered Sep 28 '22 06:09

CodaFi


You may find this list useful.

The link points exactly to the list of architecture ifdef's, here you can find links to other lists (for compiler and platform detection).

like image 40
gluk47 Avatar answered Sep 28 '22 05:09

gluk47