C development ---- # differences between if, # ifdef and # If defined

Source: Internet
Author: User
# If instructions

# If followed by an expression

# If (max = 10) | (max = 20) code... # endif

Its function is: If (max = 10) | (max = 20) is true, then the compiler will compile the code between # If and # endif (Note: It is compiled, not executed !!)

# Use of if defined

# If is followed by a macro.

# If defined (x)... code... # endif

This # If defined, no matter whether the logic of "X" is "true" or "false", it only determines whether the macro definition in front of this program defines the macro "X, if the macro X is defined, the compiler will compile... Code... Otherwise, the middle... Code... Code.

In addition, # If defined (x) can be reversed, and # If! Defined (X)

# Ifdef usage

# Use of ifdef and # Use of if defined () are consistent
# Ifndef and # If! The usage of defined () is consistent.

The last two points are emphasized:
First, these macro definitions only determine whether the code block is compiled!
Second: Don't forget # endif

C development ---- # differences between if, # ifdef and # If defined

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.