30

I am trying to understand the compiling process. We can see the preprocessor intermediate file by using:

gcc -E hello.c -o hello.i

or

cpp hello.c > hello.i

I roughly know what the preprocessor does, but I have difficulties understanding the numbers in some of the lines. For example:

 # 1 "/usr/include/stdc-predef.h" 1 3 4
 # 1 "<command-line>" 2
 # 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
 # 374 "/usr/include/features.h" 3 4

The numbers can help debugger to display the line numbers. So my guess for the first column is the line number for column #2 file. But what do the following numbers do?

1

1 Answer 1

19

The numbers following the filename are flags:

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.

Source: https://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html

4
  • Thank you. It is very useful information. I am still trying to understand how these fit into the picture. Could you explain a little bit? I will also continue my research based on your source, see how these flags been interpreted.
    – Conan
    Oct 12, 2015 at 21:05
  • I believe the 1 and 2 flags are meant to give an idea of the nested nature of the include files, so it's apparent who included who. System headers might contain constructs that are non-standard, so the 3 flag tells the compiler that those constructs are acceptable in that context. And since header files could be included by either C or C++ source, the 4 flag lets the C++ compiler know not to perform any name mangling.
    – dbush
    Oct 12, 2015 at 21:13
  • Recent versions of gcc can use the "nested nature" to show the succession of include-files where a problem lies. It's debatable whether that's useful, since the newer versions haven't offered newer type-checking or better analysis, and as a result simply magnify existing small problems. Oct 12, 2015 at 22:03
  • At this point I cannot digest much due to lack of knowledge. Will continue my study. Thanks guys.
    – Conan
    Oct 13, 2015 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.