# Ifdef Conditional compilation is actually so simple,
Read a question today:
How can I eliminate the errors caused by multiple include headers?
The solution is to use Conditional compilation. For how to solve the "symbol redefinition error caused by multiple include headers", refer to blog
Http://bbs.csdn.net/topics/350119699
Only Conditional compilation is described as follows:
These macros are used for Conditional compilation. Generally, all the rows in the source program are compiled. However, sometimes you want to compile a part of the content only when certain conditions are met, that is, to specify the compilation conditions for a part of the content. This is "Conditional compilation ". Sometimes, you want to compile a group of statements when a condition is met, and compile another group of statements when the condition is not met.
It is used to compile program segment 1 when the identifier has been defined (generally defined using the # define command). Otherwise, compile program segment 2. The # else part does not exist.
Usage:
If # idefine identifier (corresponding identifier) appears before # ifdef, run the program segment 1 for a long time; otherwise, run the program segment 2. The following simple example is written by myself:
Compile the code. Only the # else To # endif part will be compiled, and the running result will be output only: runing else part.
When # define debug is added to the sixth line, only the # ifdef to # else section will be compiled during Conditional compilation. Running result: runing main part
Advantages of Conditional compilation:
Some people may ask: what are the advantages of using Conditional compilation commands to directly use if statements without Conditional compilation commands? Indeed, this problem can be solved without the need for Conditional compilation. However, if the target program is long (because all statements are compiled), Conditional compilation can reduce compiled statements, this reduces the length of the target. When there are many Conditional compilation segments, the length of the target program can be greatly reduced.
Zookeeper