Conditional compilation of C language pre-processing commands

Source: Internet
Author: User
Tags define definition

In C,

The Conditional compilation command determines which code is compiled and which are not compiled. You can determine the compilation conditions based on the expression value or whether a specific macro is defined.

The following are some pre-processing commands:

Command usage
# Empty command, no effect
# Include contains a source code file
# Define definition macro
# Undef cancel a defined macro
# If the given condition is true, compile the following code
# Ifdef if the macro has been defined, compile the following code
# Ifndef if the macro is not defined, compile the following code
# Elif if the previous # if given condition is not true and the current condition is true, compile the following code:
# Endif end one. # if ...... # Else Conditional compilation Block
# Error stops compilation and displays error information

1. # if command

# The if command detects the constant expression following it. if the expression is true, compile the code after it until # else, # elif, or # endif appears. Otherwise, the Code is not compiled.

2. # endif command

# Endif is used to terminate # if preprocessing command.

# Include <stdio. h> DEBUG 0 DEBUG

If the # define statement is removed, the effect is the same.

3. # ifdef and # ifndef
# Include <stdio. h> DEBUG

4. # else command

# When the else command is used after a # if Command and the current # if command condition is not true, the code after # else is compiled. # The endif command terminates the preceding condition block.

# Include <stdio. h> DEBUG
5. # elif command

# Elif preprocessing commands combine the functions of # else and # if commands.

# Include <stdio. h> TWO defined TWO

 

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.