//#if Conditional Compilation//language packs typically used for each version of the product#include <stdio.h>#include<stdlib.h>//#都是预处理指令, the conditional expression must be in pre-processing//So the conditional expression must be a macro expression//Two-branch conditional compilation//#if Conditional Expressions//Code Snippet 1//#else//Code Snippet 2//#endif//#endif结束条件编译//#if, #else和C语言里的if else function, but time overhead is different//If else compiles all the code, the source will be longer and the compilation time will be longer//Large program size, more memory consumption, long running time//#if, #else只编译符合条件的语句, effectively reduce the compiled statements,//Shorten the length of the source code and shorten the program execution time//Multi-branch conditional compilation//#if conditional expression 1//Code Snippet 1// #elif conditional expression 2 //Code Snippet 2//#elif conditional Expression 3//Code Snippet 3//#elif conditional Expression 4//Code Snippet 4//#else//Code Snippet 5//#endif//detect if a macro is defined// #ifdef macro definition//Code Snippet 1//#endif//#ifdef m detects if the macro is defined, defines the execution code snippet 1, does not do anything without definition//#ifdef一般用于开启某个功能//detect if a macro is defined// #ifndef macro definition//Code Snippet 1//#endif//#ifndef m detects if the macro is defined, executes code snippet 1 without a definition, does not perform any action//#ifndef一般用于开启某个功能或者include re-include troubleshooting //For example//#ifndef OPENS//#define OPENS////define a function or perform an operation so that it is not possible to duplicate the definition of a function or operation, because this code is not executed if it is already defined//#endif#defineLangua ' d 'voidMain () {//Two-branch conditional compilation#iflangua== ' E '//The conditional expression here is a macro expressionprintf ("I am the character E, beg you elder brother let a horse! \ n");#elseprintf ("I'm the boss, you want to rebel! \ n");#endif //Multi-branch conditional compilation#iflangua== ' E '//The conditional expression here is a macro expressionprintf ("I am the character E, beg you elder brother let a horse! \ n");#eliflangua== ' d 'printf ("I am the character D, is your brother horse's brother! \ n");#elseprintf ("I'm the boss, you want to rebel! \ n");#endif //detect if a macro is defined#defineM#ifdef M System ("Color 3f");#endif //detect if a macro is defined#ifndef N System ("title Nihao");#endifSystem ("Pause");}
C language preprocessing three (conditional compilation--#if)