#if 0/#if 1 effect and usage

Source: Internet
Author: User
Tags constant

Transferred from: http://www.cppblog.com/Joe/archive/2011/05/24/147036.aspx

When commenting out chunks of code, using "#if 0" is better than using "/**/", because a comment with "/**/" to block the commented out code has nested "/**/", which leads to the commented out area of the code that is not what you want, which is easy to do when the commented out code is large. This is especially true after a period of time when the code is modified.

#if 0/#if 1 is nested-supported.

Here you'll find a description of conditional compilation (#ifdef, #else, #endif, #if等). Here are 3 things:

One, 1. Scenario 1:
#ifdef _XXXX
... Program Section 1 ...
#else
... Program Section 2 ...
#endif
This indicates that if the identifier _xxxx has been defined by the # define command, the program Segment 1 is compiled, otherwise the program segment 2 is compiled.

2: Situation 2:
#ifndef _xxxx
... Program Section 1 ...
#else
... Program Section 2 ...
#endif
The #ifndef is used here, which means if not def. Of course it is the opposite of #ifdef (if the identifier _xxxx is not defined, then execute program segment 1, otherwise execute program segment 2).

3: Situation 3:
#if constants
... Program Section 1 ...
#else
... Program Section 2 ...
#endif

This indicates that if the constant is true (not 0, whatever the number, as long as it is not 0), execute program segment 1, otherwise execute program segment 2.

Second, the nesting situation

1. Situation 1

#if constant A

... Program Section 1 ...
#else

#if constant b
... Program Section 2 ...
#else
... Program Section 3 ...
#endif #endif

This indicates that if the constant A is true (not 0, whatever the number, as long as it is not 0), the program segment 1 is executed. When the constant A is 0, the constant B is true, the program segment 2 is executed, when the constant A is 0, and constant b is 0 o'clock, the program segment 3 is executed;

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.