Multi-Line Comments Nested in Single Line Comments 
Author Message
 Multi-Line Comments Nested in Single Line Comments

What does the ANSI standard say about lines like the following:

// this is a comment /* inside of a comment */

I'm working on a tool which has trouble parsing these kinds of
lines although they are pretty common in a lot of the windows header
files.

David Friedman



Tue, 06 Jan 2004 02:39:36 GMT  
 Multi-Line Comments Nested in Single Line Comments

Quote:

> What does the ANSI standard say about lines like the following:
> // this is a comment /* inside of a comment */

     6.4.9 Comments
      ...
     Except within a character constant, a string literal, or a comment,
     the characters // introduce a comment that includes all multibyte
     characters up to, but not including, the next new-line character.
     The contents of such a comment are examined only to identify
     multibyte characters and to find the terminating new-line character.

Considering

// this is a comment /* inside of a comment */

those // at the beginning make it all just a comment.

 - Larry Weiss



Tue, 06 Jan 2004 04:57:48 GMT  
 Multi-Line Comments Nested in Single Line Comments
Larry,

<snip>

Quote:
>      6.4.9 Comments
>       ...
>      Except within a character constant, a string literal, or a comment,
>      the characters // introduce a comment that includes all multibyte
>      characters up to, but not including, the next new-line character.
>      The contents of such a comment are examined only to identify
>      multibyte characters and to find the terminating new-line character.

while i could be wrong, i believe this to be a c9x interpretation
of the comments. i think previous version of the standard did
not allow for such comments, while they have been supported by
some major compilers as extensions.

of course, there is nothing in the original post that says *which*
standard. the only reason i am making this comment is because
c99 is not widely supported by compilers yet (i suppose gcc 3.0
starts down that road, but its flaky. i have no real data
to back this statement up though)

anyway, just my 2 cents

hth,

denis



Tue, 06 Jan 2004 13:39:06 GMT  
 Multi-Line Comments Nested in Single Line Comments
Quote:

> Larry,

> <snip>
> >      6.4.9 Comments
> >       ...
> >      Except within a character constant, a string literal, or a comment,
> >      the characters // introduce a comment that includes all multibyte
> >      characters up to, but not including, the next new-line character.
> >      The contents of such a comment are examined only to identify
> >      multibyte characters and to find the terminating new-line character.

> while i could be wrong, i believe this to be a c9x interpretation
> of the comments. i think previous version of the standard did
> not allow for such comments, while they have been supported by
> some major compilers as extensions.

> of course, there is nothing in the original post that says *which*
> standard. the only reason i am making this comment is because
> c99 is not widely supported by compilers yet (i suppose gcc 3.0
> starts down that road, but its flaky. i have no real data
> to back this statement up though)

Yes, the quote is from the C99 standard.

HTH,
--ag

--
Artie Gold, Austin, TX  (finger the cs.utexas.edu account for more info)

--
"Those who can, do. Those who can't, teach. Those who can't teach, teach
gym." -- W. Allen



Tue, 06 Jan 2004 14:18:06 GMT  
 Multi-Line Comments Nested in Single Line Comments

Quote:

> >      6.4.9 Comments
> >       ...
> >      Except within a character constant, a string literal, or a comment,
> >      the characters // introduce a comment that includes all multibyte
> >      characters up to, but not including, the next new-line character.
> >      The contents of such a comment are examined only to identify
> >      multibyte characters and to find the terminating new-line character.

> while i could be wrong, i believe this to be a c9x interpretation
> of the comments. i think previous version of the standard did
> not allow for such comments, while they have been supported by
> some major compilers as extensions.

True, it didn't. In that case, // This is... would be a syntax error. In
the only C Standard that does allow // comments, the above quote holds.
In non-standard extensions that allow // comments, well, anything goes;
consulte thy compyler dockumentes.

Richard



Tue, 06 Jan 2004 15:39:35 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. \ at end of line = comment in next line?

2. C/C++ macro to comment out a line

3. // comments and line splicing \

4. My comments to X3J11 (1000 lines)

5. Line numbers and comments ...

6. Comment Line in VC++ IDE

7. ANN: Add-In for Visual C++ to Sort Lines, Copy Comments

8. #define and comments on the same line

9. Looking for program to count non commented source lines

10. Looking for Tools witch count the number of lines of my files cpp and comments

11. CEdit multiline Get line by line ?!?

12. multiple-line CEdit set multi-line text

 

 
Powered by phpBB® Forum Software