C pre-processor, processor

Source: Internet
Author: User

C pre-processor, processor

The C Preprocessor is not a component of the compiler, but a separate step in the compilation process. The C Preprocessor is just a text replacement tool that instructs the compiler to complete the necessary preprocessing before the actual compilation.

All Preprocessor commands start with. It must be the first non-null character. To enhance readability, Preprocessor commands should start from the first column.

 

The following table contains all important Preprocessor commands:

Command

Description

# Define

Definition macro

# Include

Contains a source code file

# Undef

Cancel a defined macro

# Ifdef

If the macro has been defined, true is returned.

# Ifndef

Returns true if the macro is not defined.

# If

If the given condition is true, compile the following code:

# Else

# If alternative

# Elif

If the previous # if condition is not true and the current condition is true, compile the following code:

# Endif

End one # if ...... # Else Conditional compilation Block

# Error

When a standard error occurs, an error message is output.

# Pragma

Use the standardization method to publish special commands to the Compiler

# Line

Provide the row number used for Compiler Information

 

Predefined macros

Ansi c defines many macros. These macros can be used in programming, but they cannot be directly modified.

Macro

Description

_ DATE __

The current date, which is a character constant in the format of "mmm dd yyyy.

_ TIME __

The current time, which is a character constant in the format of "HH: MM: SS.

_ FILE __

Contains the current file name, A String constant.

_ LINE __

Contains the current row number, a decimal constant.

_ STDC __

When the compiler is compiled in ANSI standard, it is defined as 1.

_ Stdc1_version __

If the compiler complies with C99, the macro value is 199901L, which is not defined in other cases.

_ Stdc1_hosted __

The current macro is a host system. The macro value is 1 and the current macro value is 0.

_ Stdc1_iec0000559 __

If the floating point implementation follows the IEC 60599 standard, the macro value is 1, otherwise it is not defined.

_ Stdc1_iec1_5591_complex __

If the plural operation follows the IEC 60559 standard, the macro value is 1. Otherwise, it is not defined.

_ Stdc1_iso000046 __

It is defined as a long integer constant.

 

Preprocessor Operator

The C Preprocessor provides the following operators to help create macros:

1. Macro continuation operator (\)

A macro is usually written on a single row. However, if the macro is too long to accommodate a single row, the macro continuation operator (\) is used (\).

2. String constant operator (#)

In macro definition, when the macro parameter needs to be converted to a String constant, the string constant operator (#) is used (#). The operator used in a macro has a specific parameter or parameter list.

3. Mark and paste operator (##)

The mark-and-paste operator (#) in the macro definition merges two parameters. It allows two independent tags in the macro definition to be merged into one tag.

4. defined () Operator

The Preprocessor defined operator is used in constant expressions to determine whether an identifier has been defined using # define. If the specified identifier has been defined, the value is true (non-zero ). If the specified identifier is not defined, the value is false (zero ).

 

Parameterized macros

A powerful feature of CPP is that it can use parameterized macros to simulate functions.

Before using a macro with parameters, you must use the # define command to define the macro. The parameter list is enclosed in parentheses and must be followed by the macro name. Spaces are not allowed between macro names and left parentheses.

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.