Re: How to determine if a given line is a C/C++ comment

"Nicola Musatti" <nicola.musatti@gmail.com>
18 Aug 2006 01:04:04 -0400

          From comp.compilers

Related articles
[2 earlier articles]
Re: How to determine if a given line is a C/C++ comment haberg@math.su.se (2006-08-10)
Re: How to determine if a given line is a C/C++ comment nicola.musatti@gmail.com (Nicola Musatti) (2006-08-10)
Re: How to determine if a given line is a C/C++ comment johnmillaway@yahoo.com (John Millaway) (2006-08-10)
Re: How to determine if a given line is a C/C++ comment mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2006-08-12)
Re: How to determine if a given line is a C/C++ comment listas@nicolasb.com.ar (Nico) (2006-08-12)
Re: How to determine if a given line is a C/C++ comment gah@ugcs.caltech.edu (glen herrmannsfeldt) (2006-08-14)
Re: How to determine if a given line is a C/C++ comment nicola.musatti@gmail.com (Nicola Musatti) (2006-08-18)
Re: How to determine if a given line is a C/C++ comment zebedee@zebedee.net (zebedee) (2006-09-12)
| List of all articles for this month |

From: "Nicola Musatti" <nicola.musatti@gmail.com>
Newsgroups: comp.compilers
Date: 18 Aug 2006 01:04:04 -0400
Organization: http://groups.google.com
References: 06-08-04206-08-070
Keywords: C++, lex, syntax, comment
Posted-Date: 18 Aug 2006 01:04:04 EDT

glen herrmannsfeldt wrote:
[...]
> There is also the preprocessor to consider.


Yes, in the sense that conditional directives may impact the "actual
lines of code" count. However it would require arbitrary assumptions
for anything different from '#if 0'. I do agree that this complicates
matters somewhat.


> As I understand it, the OP is trying to understand how statement
> counts change with editing, such as through diff.
>
> Consider:
>
> #if 0
> /*
> #endif
>
> I pretty often use #if 0 to get around the non-nesting of comments,
> and would never put a partial comment in a #if 0/#endif block,
> but someone else might do it.


I believe you've got the C/C++ translation phases mixed up. Comments
are removed before preprocessor directives are interpreted, so in your
example above you are missing a comment termination sequence and
possibly an #endif directive.


Cheers,
Nicola Musatti
[I checked the C99 standard and you're right. Comments are stripped
as the source is tokenized, which happens before it handles
preprocessing directives. There may be compilers that do it the other
way, but they're not ANSI C compilers. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.