Commonly used macro compilation definition: allows code to be executed under different compilation Conditions

Source: Internet
Author: User

(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.