The following is the code of hello.c :
#include
int
main (void)
{
printf (\"Hello, world!\\n\");
return 0;
}
I used t
The fields of the preprocessor output are documented in 9 Preprocessor Output of the GNU cpp manual.
The fields are:
# linenum filename [flags]
...
Such a line means that what follows it (...
) originated at line
number linenum
in file filename
. The optional flags
are:-
‘1’
This indicates the start of a new file.
‘2’
This indicates returning to a file (after having included another file).
‘3’
This indicates that the following text comes from a system header file, so certain warnings should be suppressed.
‘4’
This indicates that the following text should be treated as being wrapped in an implicit extern "C" block.
You see that nesting arises from #include
directives, e.g.
# 1 "hello.c"
# 1 "/usr/include/stdio.h" 1 3 4
# 27 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/features.h" 1 3 4
# 375 "/usr/include/features.h" 3 4
# 1 "/usr/include/sys/cdefs.h" 1 3 4
...
tells us:
"hello.c"
start a new file "/usr/include/stdio.h"
,"/usr/include/features.h"
"/usr/include/sys/cdefs.h"
It's not easy reading.
The special "filenames"
and
will always crop up
in a context resembling:-
# 1 "hello.c"
# 1 ""
# 1 ""
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "" 2
# 1 "hello.c"
at the top of the preprocessed output for any file. Details may vary with GCC version.
As you'd guess,
and
are not real files. They
are non-file sources of preprocessor tokens that need to be represented somehow
in the output format, so they are treated as if they were files. Call them pseudo-files.
is the pseudo-file that contains the compiler's built-in macro
definitions. For the way to see the contents of this pseudo-file, browse to
GCC dump preprocessor defines.
is of course the preprocessor (usually GCC) commandline,
considered as a source of macro definitions (and possibly un-definitions), e.g.
gcc ... -DFOO=1 -UBAR ...
So your example:
# 1 "hello.c"
# 1 ""
# 1 ""
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "" 2
# 1 "hello.c"
# 1 "/usr/include/stdio.h" 1 3 4
...
represents this process:
hello.c
, and then/usr/include/stdc-predef.h
as if it was pre-included on the commandline by -include /usr/include/stdc-predef.h
, and thenhello.c
, and then/usr/include/stdio.h