Objective-CStudy NotesPreprocessingProgramIs 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. 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
Connects two tokens. Its front (or back) 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.
Iii. 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.