cpp预处理器输出无法理解? [英] cpp preprocessor output not able to understand?

查看:145
本文介绍了cpp预处理器输出无法理解?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,如果我的问题是非常基本的。我想了解预处理器cpp产生的输出。假设我有一个非常基本的下面的程序。

  #include< stdio.h> 
#include< stdlib.h>

int x = 100;
int main()
{
printf(\\\
Welcome..\\\
);
}

我执行以下命令。

  cpp main.c main.i 

in main.i

 #1/usr/include/stdio.h 1 3 4 

上面这行的含义是什么?

解决方案

gcc文档正确解释了C预处理器输出。



以下是相关章节:


来自C预处理器的输出看起来非常像输入,除了所有预处理指令行已被空行代替并且所有注释都带有空格。



源文件名和行号信息由表单行传送

 #linenum文件名标志

这些称为 linemarkers 。它们根据需要插入到输出中(但从不在字符串或字符常量内)。它们表示下面一行来自文件文件名 linenum 文件名永远不会包含任何非打印字符;它们被八进制转义序列替换。

在文件名出现零个或多个标记,它们是 1', 2', 3'或 4'。如果有多个标志,空格将它们分开。以下是标志的含义:

1 这表示新文件的开始。

2
这表示返回到一个文件(在包含另一个文件之后)。
3
这表明以下文本来自系统头文件,所以应该禁止某些警告。

4
这表明下面的文本应该被当作包装在一个隐含的externC块中。



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 ?..

解决方案

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', or4'. 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.

这篇关于cpp预处理器输出无法理解?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆