Objective-CStudy NotesPreprocessing ProgramIs the content to be introduced in this article, mainly introducesPreprocessing ProgramStatement usage,Preprocessing ProgramThe statement is marked. Let's take a look at the details.
I. # define
1. More advanced definition types
Assign an expression and anything to the symbol name. For example:
- #define TWO_PI 2*3.141592654,#define AND &&
The pre-processing program is assumed to be included in a row of the program. If the second line is required, the last character of the previous line must be the backslash (\). For example:
- #define IS_LEAP_YEAR(y) y%4==0&&y0!=0\
- ||y@0==0
Optional parameters. Predefined definition) is usually called a macro ".
2. # Operators
If a # is placed before the macro parameter in the macro definition, the preprocessing program creates a C-style constant string based on the macro parameter when calling the macro. For example:
- #define str(x) #x
- str(testing)——"testing"
- str("hello")——"\"hello"\"
3. ## Operators
Used to link two tokens. Is the macro parameter name. The Preprocessing Program uses the actual parameters provided when the macro is called, and creates a single tag Based on the parameter and the tag after # Or before. For example:
- #define printx(n) printf("%i\n",x##n);
- printx(20)——printf("%i\n",x20);
Ii. # import statements
. H-> header file or include file ).
Set a set of # import statements and input them to an independent file of xxx. h. If necessary, run the Preprocessing Program command:
# Import "xxx. h ".
# Import <……> As a result, the Preprocessing Program only searches for contained files in the special "system" header file directory. The current directory is not searched.
# Import "...... "The Preprocessing Program is in one or more file directories.
3. Conditional compilation.
It is usually used to create programs that can be compiled and run on different computer systems. It is often used to switch various statements in the program.
1. # ifdef, # endif, # else, And # ifndef statements
Port Data from one computer system to another.
2. # if and # elif Preprocessing Program Statements
Non-zero expression results -- all subsequent rows until # else, # elif, or # endif; otherwise, they are skipped.
Special Operator: # define (name) can also be used in # if statements.
3. # undef statement
Make some defined names undefined.
Summary: DetailsObjective-CStudy NotesPreprocessing ProgramI hope this article will help you!