Nested Comments in C -- A recent experience

Walter Bright bright at Data-IO.COM
Tue Mar 13 06:26:10 AEST 1990


In article <1990Mar11.065712.9798 at usenet.ins.cwru.edu> crds at pyrite.som.cwru.edu (Glenn A. Emelko) writes:
<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 compiler doesn't
<handle nested comments (like most C compilers don't).
<      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 */
<      }

I sympathize, I had exactly this problem once. Whereupon I modified my
compiler to produce the message:

        b=arg1+2*arg2;     /* Guess what, this line never gets executed */
			    ^
	Warning: nested comments are not allowed

which eliminated the problem.



More information about the Comp.lang.c mailing list