Conditional compilation in C language behaves like if...else in C ... , which is a precompiled instruction command that controls whether a piece of code is compiled.
1. Nature of conditional compilation
(1) pre-compiler selective deletion code based on conditional compilation directives
(2) The compiler does not know the existence of the Code branch
(3)if...else ... statements are branched at run time, and conditional compilation directives are branch-judged during the pre-compilation period.
(4) You can define macros from the command line
①gcc –DMarco=value file.c// for #if statements
②gcc –DMarco file.c// for #ifdef or ifndef statements
2. Meaning of conditional compilation
(1) conditional compilation allows us to compile different pieces of code according to different conditions, thus producing different target generations .code.
(2)#if ... #else ... #endif is processed by the precompiled compiler, and if...else ... statements are processed by the compiler, and must be compiled Translate into target code.
(3) in the actual project, the conditional compilation is mainly used in the following two kinds of situations:
① The different product lines share a piece of code
② differentiate between debug and release versions of compiled products
C-language Learning notes-conditional compilation