4

For gcc -E sample.c -o sample.i with the following input C program,

 #include <stdio.h>
 int main() {
   printf("hello world\n");
   return 0;
 }

the sample.i have the following output preceded by # symbols and I wonder what the line with # exactly means.

# 1 "sample.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "sample.c"
# 1 "/usr/include/stdio.h" 1 3 4
# 27 "/usr/include/stdio.h" 3 4
...
ShivaGaire
  • 2,283
  • 1
  • 20
  • 31
RSStepheni
  • 467
  • 1
  • 5
  • 6

1 Answers1

4

There are comments that help a person identify how the preprocessor expanded the various #include <...> macros and other items.

Reading these lines provides the equivalent of reading the logging messages of the preprocessor as it encounters the macros and expands them.

# 1 "sample.c"

Start on line one of the input "sample.c"

# 1 "<built-in>"

Process the built-in c pre-procssor directive (must be an implementation detail), but is presented as a fake "file".

# 1 "<command-line>"

Process the command line directive (again implementation detail), presented as a fake "file".

# 1 "/usr/include/stdc-predef.h" 1 3 4

Include (at line 1) the stdc-predef.h file, it's the start of the file, suppress warnings permitted for system header files, assure that the symbols are treated like C symbols.

# 1 "<command-line>" 2

Return from the command line "fake" file.

# 1 "sample.c"

Back in sample.c.

# 1 "/usr/include/stdio.h" 1 3 4

Now starting with file "stdio.h", suppress permitted system warnings, treat symbols in the file a C symbols.

# 27 "/usr/include/stdio.h" 3 4

And so on...

The documentation is here.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138