Why nested comments not allowed?
Raymond Chen
raymond at twinkies.berkeley.edu
Tue Feb 20 09:10:39 AEST 1990
Dear everyone who wants to argue that nested comments are "good", "easy to
implement", "has no hidden surprises":
Please present a coherent rule for nested comments for which the following
lines of code produce "expected" results:
int openquote = 34; /* " */ int closequote = 34; /* Also " */
int quote = 34; /* for a good time, type printf("*/ %c",quote) */
/* int doublequote = 34; /* " */ */ /* don't need this one: '"' */
/* printf("*/ is the close-comment token\n");
printf("/* is the \"open-comment\" token\n"); */
Any set of rules for making these pathological cases work "right" will
probably be so complicated that nobody will understand them, and in
fact you'll have MORE problems with nested comments than you do today
(because the current rules are easy to remember).
Conclusions:
(1) Don't use comments to comment out code. If you need to
comment out code, use #if 0 .. #endif. They nest nicely.
(2) There exist programs out there whose job is to help catch runaway
comments. Use them. I'll send you mine if you want one.
--
raymond at math.berkeley.edu mathematician by training, hacker by choice
More information about the Comp.lang.c
mailing list