L
Leor Zolman
Breaks existing code. I've seen source where several lines, each
ending with a comment, are commented out by replacing the first two
characters (which were spaces) with "/*". For example:
/* x = foo(); /* get result of foo */
While I certainly don't *recommend* that, it is existing practice,
and changes to the standard usually seek to minimize adverse
effects on existing code.
OK, but I see nested comments as a personal time-saving device, and the
technique above as some kind of parallel time-saving device. Clearly the
two devices should not be placed in close proximity, and in any sane shop
they wouldn't be...or not for very long.
I don't see how inserting a
#if 0
and a
#endif
is any more trouble than inserting comment delimiters. It's a grand
total of 9 more characters (10 if you count the newlines, but
commenting out code without putting the delimiters on a separate
line is a barbarism not to be contemplated).
Well, and then there's finding the shift key, finding the # key (twice for
both), being in a hurry so having to backspace a few times while typing it
all out, .... ;-)
#if 0 is *better* than a comment for trying two different forms,
since you can put them into the two halves of a #if / #else and
switch between them by changing a single character (0 becomes 1).
Yes, there I'm now inclined to agree with you.
If by "preprocessor symbol" you mean a macro as the operand of
the "defined" operator (or of #ifdef), none is required. But you
*can* use one if you'd like to be able to select which form you're
using without editing the source (in typical implementations) - a
luxury not available if you use comments to remove code.
So long as it's a string of legal pp-tokens, you can do the same
with #if 0. No need for it to be legal C code.
Okay, some pros and cons. BTW, I don't use nested comments any more at all,
just because of the hassle of dealing with the compiler settings I'd have
to finagle across all the platforms I currently play musical compilers
with. But I'll probably end up adopting your #if 0 / #if 1/ #else
suggestion for switching alternate blocks of code.
Thanks,
-leor