K
Kenneth Brody
Ryan Reich wrote:
[...]
Actually, neither of those is a "nested comment". The first is a
comment with "/*" within it, and the second is a comment with "//"
in it.
Unless, that is, your compiler supports nested /*...*/ comments, in
which case the first example hasn't ended the comment.
/* This is a comment /* with a nested comment */ inside of it. */
Consider this case where the compiler doesn't really "nest" /*...*/
comments. (Which is what you are assuming, given your first example.)
void foo()
{
... a bunch of code ...
/* the following code was commented out on 1-jan-2000 by xyz
foo
bar
i++; /* I added this, having not noticed that this is within
* commented-out code.
*/
bar
foo
*** end of 1-jan-2000 comment */
... some more code ...
}
[...]
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
[...]
Nested comments are never ambiguous; only if you are really looking for
complication do they become ambiguous, and in that case, they're just as
ambiguous for // as for /* */. Consider:
/* A comment /* with a comment inside */
// A comment // with a comment inside
Syntactically, they're identical. The most obvious way of parsing comments
will not notice the nesting. How is it more ambiguous for the first whether
or not there's a syntax error? It's possible, even likely, that a human might
find the latter to be clearer, but who cares what humans think about how C
code is parsed? Only the compiler really cares, and the compiler is not
fooled by visual cues like which opening delimiter is closer to the closing
one, when the standard is that "the closing one" matches the _first_ opening
one, not the nearest.
Actually, neither of those is a "nested comment". The first is a
comment with "/*" within it, and the second is a comment with "//"
in it.
Unless, that is, your compiler supports nested /*...*/ comments, in
which case the first example hasn't ended the comment.
/* This is a comment /* with a nested comment */ inside of it. */
Your first objection, about commenting out large blocks, is not really valid
since to do so with /* requires only two insertions, and you can even make
those on their own new lines, which requires no interference with the existing
text at all. It's actually easier to comment out large blocks this way than
with //.
Consider this case where the compiler doesn't really "nest" /*...*/
comments. (Which is what you are assuming, given your first example.)
void foo()
{
... a bunch of code ...
/* the following code was commented out on 1-jan-2000 by xyz
foo
bar
i++; /* I added this, having not noticed that this is within
* commented-out code.
*/
bar
foo
*** end of 1-jan-2000 comment */
... some more code ...
}
[...]
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>