Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Because missing end deliminators is error prone and often viewed as a mistake, it is recommended that this approach not be used to comment out code.

Compliant Example

Comment out blocks of code using condition compilation (e.g., #if or #ifdef).

Code Block

#if 0  /* use of critical security function no longer necessary */
security_critical_function();
/* some other comment */
#endif

Non-Compliant Example

The following are some additional examples of comment styles that are confusing and should be avoided:

Code Block

// */ // comment, not syntax error
...
f = g/**//h; // equivalent tof = g / h;
...
//\
i(); // part of a two-line comment
...
/\
/ j(); // part of a two-line comment
...
/*//*/ l(); // equivalent to l();
...
m = n//**/o
+ p; // equivalent tom = n + p;

Compliant Example 1

Use a consistent style of commenting:

Code Block

// Nice simple comment

int i; // counter

Compliant Example 2

Use a consistent style of commenting:

Code Block

/* Nice simple comment */

int i; /* counter */

References