Nested Comments in C -- A recent experience

David P. Schaumann dave at cs.arizona.edu
Mon Mar 12 04:01:05 AEST 1990


In article <1990Mar11.065712.9798 at usenet.ins.cwru.edu>, crds at pyrite.som.cwru.edu (Glenn A. Emelko) writes:
|Well, for once in a long while I've got a few cents to throw in. Just got
|done spending 3 hours looking for a "bug" which turned out not to be a "bug"
							    ^^^^^^^^^^^^^^^^^
|at all; rather it went undetected as a programming error BECAUSE our C
					^^^^^^^^^^^^^^^^^
What's the difference?

|compiler doesn't handle nested comments (like most C compilers don't).  The
|code looked like the example below (not the actual code, but similar):
|
|      function(arg1,arg2) {
|        int a,b,c;
|        a=arg1*arg2+3;    /* Oops, we're going to forget to close this comment
|        b=arg1+2*arg2;     /* Guess what, this line never gets executed */
|        c=a+b;
|        return(c);         /* Here's the bogus results, Mr. caller */
|      }

  [ description of search for bug deleted ]

|If the C compiler understood nested comments it would FORCE programmers to
|match them, preventing wasted hours of debugging on annoying problems like
|the above at the expense of a few milliseconds of additional compile time.
|
|Glenn Emelko

The C compiler here (gcc) has an option which will warn of a comment start
sequence (/*) embedded in a comment.  I agree that this should have been
caught by the compiler, but I think adding nested comments is the wrong
solution.  Rather, the compiler should always flag the occurance of /*
within a comment unless explicitly told to shut up about it.  Does anyone know
what ANSI says about this?

Dave Schaumann
dave at cs.arizona.edu



More information about the Comp.lang.c mailing list