C + + #if 1

Source: Internet
Author: User

When you comment out large chunks of code, use the"#if 0"than using"/**/"Better, because with"/**/"Comment on a larger paragraph to prevent the commented out code from having nested"/**/", this causes the commented out area of the code to be not the range you want, especially if the commented out code is large, particularly if the code is modified over a period of time. Here by the way conditional compilation (#ifdef,#else, #endif, #if等) for clarification. Here are 3 things:1. Scenario 1: #ifdef _xxxx ... Program Section 1 ...#else..... Program Section 2 ...#endifThis 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. Example:#defineNumAnd ......... #ifdef, ..., ..., and so on.---- ----- ---------------NUM printf (()."num has been defined before! :) \ n"); #elseprintf ("Num has never been defined before! :(\ n"); #endif} If the program starts with#defineNUM, which is defined by NUM, will, of course, execute the first printf when it encounters the #ifdef num below. Otherwise a second printf will be executed.I think, with this, can be very convenient to open/turns off a specific feature for the entire program. 2: Scenario 2: #ifndef _xxxx ... Program Section 1 ...#else ..... Program Section 2 ...#endifThe #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).  The example is not to be lifted. 3: Situation 3:#ifConstant..... 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. If there is an # # need shelf write

C + + #if 1

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.