(1) _ optimize _: used to determine release and Debug. When _ optimize _ is selected, the code can be executed during release, but not during debug. Example:
| 12345 |
#ifndef __OPTIMIZE__ // In debug modeelse // In the release mode#endif |
(2) _ i386 _ and _ x86_64 _: used to judge the simulator environment and the real machine environment. The code that meets this condition is only executed in the simulator. The sample code is as follows:
| 1234567 |
#if defined (__i386__) || defined (__x86_64__) // Run the command in the simulator.#else // Execute on a real machine#endif |
(3) _ iphone_ OS _version_max_allowed: The current compiled SDK version, which can be compared with macro definitions such as _ iphone_9_0 for code execution in different versions. Example:
| 12345 |
if (__IPHONE_OS_VERSION_MAX_ALLOWED == __IPHONE_9_0) { // If the current SDK version is 9.0, execute the code here }else{ // Otherwise, run the following command: } |
[16] pre-compiled macro # ifdef # else # endif
| 12345 |
#ifdef **** // Code 1else // Code 2#endif |
This means that if the identifier *** has been defined by the # define command, code 1 is compiled; otherwise, code 2 is compiled.
There are also # ifndef, which is the opposite of # ifdef.
Commonly used macro compilation definition: allows code to be executed under different compilation Conditions