问题
Sorry if my question is very basic. I would like to understand the output produced by the preprocessor cpp. Let's say i have a very basic following program.
#include <stdio.h>
#include <stdlib.h>
int x=100;
int main ()
{
printf ("\n Welcome..\n");
}
I execute the following command.
cpp main.c main.i
in main.i
# 1 "/usr/include/stdio.h" 1 3 4
What is the meaning of the above line ?..
回答1:
The gcc documentation explains the C preprocessor output aptly.
Here are the relevant sections:
The output from the C preprocessor looks much like the input, except that all preprocessing directive lines have been replaced with blank lines and all comments with spaces. Long runs of blank lines are discarded.
Source file name and line number information is conveyed by lines of the form
# linenum filename flagsThese are called linemarkers. They are inserted as needed into the output (but never within a string or character constant). They mean that the following line originated in file filename at line linenum. filename will never contain any non-printing characters; they are replaced with octal escape sequences.
After the file name comes zero or more flags, which are
1,2,3, or4. If there are multiple flags, spaces separate them. Here is what the flags mean:
1This indicates the start of a new file.2This indicates returning to a file (after having included another file).3This indicates that the following text comes from a system header file, so certain warnings should be suppressed.4This indicates that the following text should be treated as being wrapped in an implicit extern "C" block.
来源:https://stackoverflow.com/questions/9534798/cpp-preprocessor-output-not-able-to-understand