Effective C ++ 2e Item4

zhaozj2021-02-11  201

Terms 4: Try to use C -style notes

The old C commentary syntax can also be used in C , and C newly inventive row tail commentary is also there. For example, the following scenario: IF (a> b) {// int TEMP = a; // swap a and b // a = b; // b = Temp;

Suppose you have to comment out this code block for some reason. From the perspective of software engineering, the programmer written in this code is also very good.

His initial code also wrote a comment to explain what the code is doing. Use the syntax in the form of C to comment out this block

The initial annotation embedded inside is not affected, but if you choose a C style annotation, you will have a serious error: if (a> b) {/ * int TEMP = a; / * swap a and b * / a = b; b = Temp; * /}

Note how the comment in the tangible code block is inadvertently ended in advance of the comment to comment out of the entire code block.

C style annotations Of course, there is also its value. For example, they cannot be replaced in the header files to be processed in the C and C compilers.

. Despite this, as long as it is possible, you'd better use C -style annotations.

It is worth pointing out that some old-written pre-processing programs do not know about handling C -style annotations, so I like this below.

When you don't like the idea: #define light_speed 3e8 // m / sec (in a vacuum)

For preprocessors that are not familiar with C , the annotation of the end is a part of the macro! Of course, the status of the elephant 1 said

If you don't use pretreatment, you will define constants anyway.

转载请注明原文地址:https://www.9cbs.com/read-4485.html

New Post(0)