cpp preprocessor output not able to understand?

走远了吗. 提交于 2019-12-02 23:41:42

问题


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 flags

These 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, or 4. If there are multiple flags, spaces separate them. Here is what the flags mean:

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.



来源:https://stackoverflow.com/questions/9534798/cpp-preprocessor-output-not-able-to-understand

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!