Debugging information in GCC preprocessor output

2020-03-26 04:25发布

问题:

I was inspecting the preprocessed output generated by GCC, and I see a lot of these in the .i file that I generated using the -save-temps flag:

# 8 "/usr/include/i386-linux-gnu/gnu/stubs.h" 2 3 4

What do the numbers before and after the absolute path of stubs.h mean? It seems to be some kind of debugging information that is inserted by the preprocessor and allows the compiler to issue error messages referring to this information. These lines do not affect the program itself, but what specifically is each number for?

回答1:

Based on the documentation the number before the filename is the line number. The numbers after the file name are a flag and mean the following:

  • 1 indicates the start of a new file.
  • 2 indicates returning to a file (after having included another file).
  • 3 indicates that the following text comes from a system header file, so certain warnings should be suppressed.
  • 4 indicates that the following text should be treated as being wrapped in an implicit extern "C" block.