[gnu.gcc] spotting syntax errors

sr16+@ANDREW.CMU.EDU (Seth Benjamin Rothenberg) (07/13/89)

I recently tried to compile a program with an unclosed comment in it.

This caused a syntax error to be detected immediately
following the next (correctly closed) comment.
(a function header ended up being commented out.)

I thought of a simple was to trap this error.
Since nested comments generally do cause errors, they should
be disallowed.  Thus, when the compiler spots a nested comment,
it could flag it, including a pointer to original (unclosed) comment.

A sample program with this error follows:
#include <stdio.h>

/* this is a buggy program
main()
{         /* another comment to throw you off */
   char hi[5];

   strcpy(hi, "hi");  /* copy a value in */
   puts(hi);
}
note: char hi[5]; is legal if "main() {" is commented out,
so the first error message occurs much later...

rejecting nested comments would make finding this error easier.

lacey@batcomputer.tn.cornell.edu (John Lacey) (07/13/89)

In article <YYivPOy00WB4Q9X41M@andrew.cmu.edu> sr16+@ANDREW.CMU.EDU (Seth Benjamin Rothenberg) writes:
>I recently tried to compile a program with an unclosed comment in it.
> [ ... ]
>Since nested comments generally do cause errors, they should
>be disallowed.  Thus, when the compiler spots a nested comment,
>it could flag it, including a pointer to original (unclosed) comment.
> [ ... ]
>rejecting nested comments would make finding this error easier.

Well, pointers generally do cause errors also (or at least as much as
nested comments) and are even harder to debug.  Therefore, to protect
ourselves, pointers should be disallowed.

No, no, no.  If you want a fascist language, fine.  Use one.  Do not
try to change every language to your fascist ideal.  Nested comments
are, like pointers, extremely useful.  For one thing, they allow
to comment out blocks of code without having to worry about comments
inside the block. (Though I confess, I usually use a #ifdef OBSOLETE
or some such to "delete" blocks in that fashion.)

More importantly, why did you post this to gnu.gcc, and not comp.lang.c?
Follow-ups there, if you all please.
-- 
John Lacey           |  Internet:  lacey@tcgould.tn.cornell.edu
running unattached   |  BITnet:    lacey@crnlthry
                     |  UUCP:      cornell!batcomputer!lacey
"Whereof one cannot speak, thereof one must remain silent."  ---Wittgenstein

spike@bu-cs.BU.EDU (Spike) (07/13/89)

In article <YYivPOy00WB4Q9X41M@andrew.cmu.edu> sr16+@ANDREW.CMU.EDU (Seth Benjamin Rothenberg) writes:
<I recently tried to compile a program with an unclosed comment in it.
	[...]
<I thought of a simple was to trap this error.
<Since nested comments generally do cause errors, they should
<be disallowed.  Thus, when the compiler spots a nested comment,
<it could flag it, including a pointer to original (unclosed) comment.

	From the gcc man page (and of course in the info file):

     -Wcomment
          Warn whenever a comment-start sequence `/*' appears  in
          a comment.

->Spike
Software Tool & Die     The right choice.