Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the numbers mean in the preprocessed .i files when compiling C with gcc?

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?

like image 514
Conan Avatar asked Oct 12 '15 19:10

Conan


People also ask

What are .I files in C?

i file is an output of the C or C++ preprocessor. It is usually this extension which is characteristic of files created as the preprocessor output. The preprocessor performs primary transformations of the source program text using only lexical analysis.

Which command is used to check preprocessed code?

If this file is called 'test. c' the effect of the preprocessor can be seen with the following command line: $ gcc -E test. c # 1 "test.

How can I see my code after preprocessing?

Yes. Pass gcc the -E option. This will output preprocessed source code. If your compiler commands already has a parameter like -o something.o you may also want to change it to -o something.

What is the output of the preprocessor?

In computer science, a preprocessor (or precompiler) is a program that processes its input data to produce output that is used as input to another program. The output is said to be a preprocessed form of the input data, which is often used by some subsequent programs like compilers.


1 Answers

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

like image 77
dbush Avatar answered Sep 19 '22 23:09

dbush