In C # If 0 and # If 1

Source: Internet
Author: User

When comment out a large partCode"# If 0" is better, because the comments with "/**/" larger segments should prevent nested "/**/" in the commented-out code "/**/", this will cause the commented-out code area to be out of the scope you want. This is often the case when the commented-out code is large, especially when the code is modified after a while.

Here, Conditional compilation (# ifdef, # else, # endif, # If, etc.) is described. There are three situations: 1. Case 1: # ifdef _ XXXX...ProgramSection 1... # else... procedure 2... # endif 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: # define num ..................................... .. # ifdef num printf ("previously defined num! :) \ N "); # else printf (" no definition of num before! (\ N "); # endif} if there is a line # define num at the beginning of the program, that is, num is defined. When the # ifdef num below is met, of course the first printf is executed. Otherwise, the second printf will be executed. In my opinion, you can easily enable/disable a specific function of the entire program. 2: Case 2: # ifndef _ XXXX... procedure 1... # else... procedure 2... # endif # ifndef is used here, which indicates if not def. Of course, it is the opposite of # ifdef (if the identifier _ XXXX is not defined, the execution segment 1; otherwise, the execution Segment 2 ). This is not an example. 3: Case 3: # If constant... procedure 1... # else... procedure 2... # endif indicates that if the constant is true (not 0, any number, as long as it is not 0), the execution of the program segment 1; otherwise, the execution of the program segment 2. If yes # If you need to write the code in the top level

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.