sps sps -4 years ago 82
C Question

Supress comments in output of "gcc -E" preprocessed code

For a simple C program I did

gcc -E hello.c -o hello.pp
to see how the program looks after preprocessing.

In the output file I can see many lines which start with
#
, that look like comment. What are these lines?

How can I see only the C code, without those comments?

Below is a snippet:

user $ gcc -E hello.c -o hello.pp
user $ tail -n 15 hello.pp

extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;

extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
# 943 "/usr/include/stdio.h" 3 4

# 3 "hello.c" 2
int main()
{
printf("Hello world \n");

return 0;
}
user $

Answer Source

"How can I see only the C code, without those comments ?"

You can use gcc with options -E -P to get rid of the # lines of the preprocessor output.

From gcc documentation:

-P

Inhibit generation of linemarkers in the output from the preprocessor. This might be useful when running the preprocessor on something that is not C code, and will be sent to a program which might be confused by the linemarkers.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download