C + + Prime: Preprocessor

Source: Internet
Author: User

A preprocessing function used by C + + programs is a header file protector, and the header file protector relies on preprocessing variables. There are two types of preprocessing variables: defined and undefined, #define指令把一个名字设定为预处理变量, and the other two directives check whether a given preprocessing variable is already defined: #ifdef当且仅当变量已定义的时候为真, #inndef当且仅当变量未定义时为真. Once the check results are true, follow-up operations are performed until #endif is encountered.

These features can be used to effectively prevent duplicate inclusions from occurring:

#ifndef Sales_h #define Sales_h     ... #endif

When a Sales.h is included for the first time, #ifndef的检查结果为真, the preprocessor performs the subsequent operation sequentially until #endif is encountered. At this point, the value of the preprocessing variable sales_h becomes defined, and the Sales.h is copied into the program. If you include Sales.h again later, the #ifndef check result is false, and the compiler ignores the part between #ifedef and #endif.

C + + Prime: Preprocessor

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.