[C] Why do people write comments using /* ... */ ?
There's something I don't understand and has been bugging me for a while. After browsing the GPL'ed C source code for a lot of programs I noticed that people will often write code comments by using the "/* ... */" notation rather than "//". For example consider the following three comments:
Code:
/* Thoughts? |
Use #ifdef 0 to comment out blocks of code.
|
The // style comment was introduced to C in the C99 standard. Before that, /* ... */ (and #ifdef 0 as dugan pointed out) was the only valid way to comment C code.
|
I also find it annoying. I always use // comments, except when excluding code.
|
Ah I see. The "/* ... */" notation predates the "//". Now it makes sense.
|
Do it any way that you prefer, but, within a single module or application, do it consistently. Follow the practices of the folks who worked on the code earlier.
|
i'll confess to a bad habit. i block comment like this
Code:
/*/ |
I prefer block-comments to line-comments because word-wrapping (as done for example by mail clients) will not break the code. There is no compelling argument for why line-comments are better.
|
^ line-comments are easier to type.
|
No braces around single-statement if bodies are easier to type as well, but omitting them is a bad idea. For me “easier to type” is not a compelling argument in this instance (and if you're using reasonable editor you probably can configure it to enter comments with some simple keystroke).
|
I find it more useful to use // for comments and /**/ for excluding code. I don't care how easy or difficult it is to type, I care about functionality. It is true that #ifdef can also be used in case someone used exclusively /**/ for comments.
|
As many have said, the rules are flexible, also because of the evolution of how comments can be added to code.
I have to admit to being consistently, inconsistent: Code:
/* Code:
/* ... */ Code:
while(1) { /* I never put a comment here */ I will use "//" to comment out one or two lines, for instance if I have a "potential fix" or even one that's definitely a fix; I may copy the line to change, then use // to comment out the original and make my change in the new copy so that I can leave the original code for a while. Similarly I may use "//" when appending a comment to the end of a line, merely being lazy as a typist. To comment out code blocks, I do use #if 0 |
I see absolutely nothing wrong with using /* */
both styles are perfectly valid so there should be no reason for it to irritate you. That said, I HATE #if 0 It is very non-intuitive and many syntax-highlighters will not detect it so it is east to miss that it is "commented" out |
Quote:
|
For a block with no */ I use /* */
Otherwise I guess you would have to resort to something like that. But I avoid it because it is hard to read |
All times are GMT -5. The time now is 05:02 PM. |