# If defined

Source: Internet
Author: User

Because for a largeProgramWe may need to define many constants (whether in the source file or header file), so when we sometimes consider defining a constant, we must return to check whether the original constant is defined, however, this is very troublesome. the IF Defined Macro provides a solution for this situation. for example:

# Define ....
# Define ....
........
........
# Define a 100
.......
At this point, we should check whether a is defined (assuming we cannot remember this), or we should add the following sentence to a different value:
# If defined
# UNDEF
# Define a 200
# Endif
The preceding statement checks whether a is defined. If it is defined, use the # UNDEF statement to undefined it and redefine a as 200.

Similarly, check whether a is defined:
# Ifndef A // if A is not defined
# Define a 100
# Endif

In the macro used above: # UNDEF is undefined, # ifndef is short for if not defined, that is, if not defined.

This is the unique role of # If defined!

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.