Process: pre-processing, compiling, connecting
1, pre-processing: not C + + statements, not add; must start with #
2, compile: First analysis after synthesis, storage allocation, target code generation
3, Connection: relocation between different files processing
preprocessing commands
{macro definition, file contains, conditional compilation}
One, the macro definition
Replace a macro name with a character literals
1. Macros with no parameters
#define Macro Name character text
(1) The name of the macro is named by the identifier, generally all uppercase, the character Rune can be any (including Key Words )
(2) String constants, part of an identifier is not replaced (just part of the whole)
(3) The same macro should not be defined more than once, first canceled, then defined, #undef
(4) The scope of the macro: Start with # define and end with #undef (default to the end of the source program)
(5) Macros are typically defined at the beginning or the header file
(6) Macro definitions allow nesting, meaning that defined macro names can be referenced in character literals
2. Macros with parameters
#define Macro Name (parameter table) character text
(1) There is no space between the macro name and the parentheses, otherwise it is understood
(2) Replace the parameters first
Second, the document contains
1, <> only in the system path lookup, call the standard library
2, "" First in the project to find, and then in the system to find, call their own written header files
3. Header files typically contain: function declarations, global constants, global variables, type declarations, macro definitions
Third, conditional compilation
1. #define定义条件
2, #ifdef, #ifndef
#define // defined first, regardless of the value
#ifdef criteria Field ... // Program code One #else ... // Program code two #endif
Ifndef is the opposite of ifdef.
3. #if
#if Constant expression //can only use define expressions ... // Code Snippet 1 #elif ... // Code Snippet 2 #else ... // Code Snippet 3 #endif
4, # ifdef=# if defined; #ifndef = #if!defined;
Iv. Other Orders
1. #error: Display information and stop compiling
2. #pragma once: only one time (open) is included at compile time
3. #line
Program Cycle and preprocessing