Objective-C preprocessing

Source: Internet
Author: User

Objective-C preprocessingProgram parsing, IntroductionPreprocessingThe usage of statements in the program,PreprocessingProgram Statements are marked with #), including # define statements, # import statements, and Conditional compilation.Objective-c preprocessing, Objective-c program design, objective-c program compilation,PreprocessingProgram Statement.

# Define statement

1. More advanced definition types

Assign an expression and anything to the symbol name. For example:

The following is the reference content: # define TWO_PI 2*3.141592654, # define AND & Pre-processing program hypothesis definition is 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:

Reference content: # define IS_LEAP_YEAR (y) y % 4 = 0 & y0! = 0 \ | y @ 0 = 0 can contain 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:

The following references: # define str (x) # x str (testing) -- "testing" str ("hello") -- "\" hello "\" 3, # Operator

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:

The reference content is as follows:/***** desteps.com * 2011-8-15 *****/# define printx (n) printf ("% I \ n", x # n ); printx (20) -- printf ("% I \ n", x20); # import Statement
. 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:

 
 
  1. # Import "xxx. h ".
  2. # 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.
  3. # Import "...... "The Preprocessing Program is in one or more file directories.

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-C preprocessingThe content of the program has been introduced. I hope this article will help you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.