Objective-C Preprocessing Program

Source: Internet
Author: User

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:

 
  
  
  1. # 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:

 
  
  
  1. # Define is_leap_year (y) Y %4= 0 & y0! = 0 \
  2. | 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:

 
  
  
  1. # Define STR (x) # x
  2. STR (testing) -- "testing"
  3. 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:

 
  
  
  1. # Define printx (n) printf ("% I \ n", X # N );
  2. 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.

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.