Re^2: Why nested comments not allowed?

Derek R. Foster dfoster at jarthur.Claremont.EDU
Wed Feb 21 04:39:23 AEST 1990


>In article <13706 at cbnewsc.ATT.COM> dalenber at cbnewsc.ATT.COM (Russel Dalenberg) writes:
>>And what will you do when trying to comment out code that contains the
>>"end of comment" sequence?
>>	printf("A comment is ended with */");

Maybe I'm just strange, but I think that this whole issue of
"what will you do if your code contains start/end comment characters" is
missing an important point. It seems to me that putting a start or end
comment in a string literal (like above) is a HORRIBLE programming practice
whether you can have nested comments or not. It's just asking to be 
accidentally matched with some other part of a comment. Couldn't you avoid 
the whole issue by just doing something like :

  printf("A comment is ended with *\/");

(I'm not sure if this is portable) or else you could just go

  printf("A comment is ended with *""/");

or else, as a last resort,

  printf("A comment is ended with *%c",'/');

These don't seem like too much trouble given the relatively few times you
will ever need to do this, and they will not only save you from problems
with nested comments (now, your code doesn't care), it will also save you
from potentially forgetting to close one of your comments, only to have
it matched somewhere you didn't expect...

Just my 2c.

Derek Foster



More information about the Comp.lang.c mailing list