warning: multi-line comment (why?)

Jan Dvorak johnydog@go.cz
Tue Sep 19 09:05:00 GMT 2000


On Mon, Sep 18, 2000 at 12:04:19PM +0200, Jamie Lokier wrote:
> Richard Henderson wrote:
> > > What is the point of this warning?  Shouldn't the preprocessor
> > > just ignore everything between the // and the end-of-line?
> > 
> > No, backslash-newline conversion happens before comments
> > are discarded.  You really do have a multi-line comment;
> > one that would be dangerous if your next line weren't a
> > comment as well.
> 
> But the next line _is_ a comment so the warning is inappropriate here.
>
> If this were a very unlikely situation, fair enough.  But people do
> comment out multi-line macros from time to time using `//', and those
> will trigger the warning.

If you comment out macros during development, you may ignore this warning.
If you need commented macro in release, you have to comment it by /**/.

Multiline comment are dangerous, and even if next line begins with '//', it
is not the right way.

> It can't be too hard to skip whitespace and then check for `//' on the
> next line I'm sure.

I think it can be difficult. Referring to cpplex.c:

/* Skip a C++ line comment.  Handles escaped newlines.  Returns
   non-zero if a multiline comment.  The following new line, if any,
   is left in buffer->read_ahead.  */
static int
skip_line_comment (buffer)
     cpp_buffer *buffer;
{

...
      	return orig_lineno != buffer->lineno;
}

so you'll need lot of readahead and lot of work to get it working right.

Jan Dvorak <johnydog@go.cz>



More information about the Gcc mailing list