AOO
AOO

Reputation: 633

GCC preprocessor removing comments

Is it possible to instruct the GCC preprocessor not to remove comments when processing files?

Upvotes: 5

Views: 4061

Answers (3)

Roger Pate
Roger Pate

Reputation:

man gcc and use / -C (slash, space, dash, capitcal C) to make less (which is probably your pager program) search for the -C option, use n to search again (the description is the 3rd hit). Related options are both above and below.

Upvotes: 2

TheGrandWazoo
TheGrandWazoo

Reputation: 2897

GCC has the -C option to preserve comments.

`-C'
     Do not discard comments.  All comments are passed through to the
     output file, except for comments in processed directives, which
     are deleted along with the directive.

     You should be prepared for side effects when using `-C'; it causes
     the preprocessor to treat comments as tokens in their own right.
     For example, comments appearing at the start of what would be a
     directive line have the effect of turning that line into an
     ordinary source line, since the first token on the line is no
     longer a `#'.

Upvotes: 7

CB Bailey
CB Bailey

Reputation: 791849

Yes, you can do it with the -C option. E.g.

gcc -C -E myfile.c

Upvotes: 2

Related Questions