Comment

C++ comment-to-end-of-line syntax is preferred over C syntax because it allows embedded comment with no concern, but in C embedded comment inadvertently puts a premature end to the comment that is supposed to comment out the code block. C comment is best for source file and function header and sometime convinience to comment-out large sections of code, while C++ comment better serve in-line with the code.

The best method for commenting-out large sections of code is:

#ifdef UNCOMMENT_CODE
  /* codes ... */
#endif
and define or not define UNCOMMENT_CODE during compilation.


It is worth pointing out that retrograde preprocessors that were written only for C don't know how to cope with C++-style comments, so the most dangerous part is using it at the end of macro:

#define LIGHT_SPEED   3e8    // m/sec (in a vacuum)
Given a preprocessor unfamiliar with C++, the comment at the end of the line becomes part of the macro! No compilation error but different meaning already.

Index