# If 1... # endif

Source: Internet
Author: User

1.

"# If 0/# If 1... # endif ", we know, the C standard does not provide single-line style annotations such as "//" in C ++, but only provides block annotation functions such, we usually use it to write descriptive comments (comments) in the Code and disable the visibility (blocking) of a code segment on the compiler during debugging. Of course, the so-called "annotation effect" and "Blocking Effect" are our subjective definitions of functions. There is no difference between the two for the pre-processor. For the former, because there will no longer be "Comments" or "code segments to be shielded" in "Comments", there will be no nested requirements, so there is usually no problem; for the latter, when we need to "block" a piece of code during program debugging, the Code may contain the aforementioned "comments" and/or "blocked sections ", at this time, the "/**/" nesting requirement is generated, but the c Standard does not allow us to do so. When you try to use the nested block annotation function, you will find that the pre-processor processes the content between the beginning of the outermost annotation and the end of the innermost annotation into the annotation, the subsequent content that ends with the end of the outermost comment is treated as "valid code"-This obviously causes several syntax errors and causes compilation to stop. Experts brainstormed and Thought of "# If 0... # endif ", which is also processed by the pre-processor and can also block a piece of code. You can also write the instructions in it, these are the same as "/**/", but they are different: First, it allows nesting (the maximum number of layers is determined by the pre-processor) second, you can change "# If 0" to "# If 1" at any time to cancel "blocking" a piece of code-excellent features, discard the clumsy! Its only drawback is that there is no "comment" text display style in the editor.

 

2.

1 #if 02 3    code4 5 #endif 

(1) Some debugging code is defined in the Code, and the code is completely ignored by the compiler. If you want the code to take effect, you only need to change # If 0 to # If 1

(2) # Another important purpose of if 0 is to be used as a comment. If the program you want to comment on is very long, # If 0 is the best at this time, so as to ensure that no mistakes will be made. (But Lin's book says never use # If 0 as a block comment.) # If 1 can make the variables in it a local variable.

(3) This structure indicates the code you wrote earlier. If you don't want to delete it, you can use this method, which is more convenient than annotation.

2014.09.23 (transfer)

# If 1... # endif

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.