Why don't C comments nest? How am I supposed to comment out code containing comments? Are comments legal inside quoted strings?
C comments don't nest mostly because PL/I's comments, which C's are borrowed from, don't either. Therefore, it is usually better to ``comment out'' large sections of code, which might contain comments, with #ifdef or #if 0 (but see question 11.19).
The character sequences /* and */ are not special within double-quoted strings, and do not therefore introduce comments, because a program (particularly one which is generating C code as output) might want to print them.
Note also that // comments, as in C++, are not currently legal in C, so it's not a good idea to use them in C programs (even if your compiler supports them as an extension).
References:
K&R1 Sec. A2.1 p. 179
K&R2 Sec. A2.2 p. 192
ANSI Sec. 3.1.9 (esp. footnote 26), Appendix E
ISO Sec. 6.1.9, Annex F
Rationale Sec. 3.1.9
H&S Sec. 2.2 pp. 18-9
PCS Sec. 10 p. 130
Read sequentially: prev next up top
This page by Steve Summit // Copyright 1995 // mail feedback