gcc预编译结果

GCC中的预编译器可以生成类似于源代码的输出,显示头文件引用和宏处理情况。输出中,预处理指令被空白行替换,注释转换为空格,连续空白行被删除。行号和文件名信息通过‘#line’标记插入,用于追踪源代码位置。预处理器还保留了源代码中的空格格式,以便于阅读。此外,输出中可能包含‘#ident’、‘#pragma’等重复指令,但它们会被适当处理以避免混淆。
摘要由CSDN通过智能技术生成

    使用gcc -E参数对源文件进行预编译,可以从结果文件发现头文件以及宏等是如何引用的,有助于分析代码的编译过程。下面是gcc中对预编译结果文件的解释:

9 Preprocessor Output

When the C preprocessor is used with the C, C++, or Objective-C compilers, it is integrated into the compiler and communicates a stream of binary tokens directly to the compiler’s parser. However, it can also be used in the more conventional standalone mode, where it produces textual output.

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.

The ISO standard specifies that it is implementation defined whether a preprocessor preserves whitespace between tokens, or replaces it with e.g. a single space. In GNU CPP, whitespace between tokens is collapsed to become a single space, with the exception that the first token on a non-directive line is preceded with sufficient spaces that it appears in the same column in the preprocessed output that it appeared in the original source file. This is so the output is easy to read. CPP does not insert any whitespace where there was none in the original source, except where necessary to prevent an accidental token paste.

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.

As an extension, the preprocessor accepts linemarkers in non-assembler input files. They are treated like the corresponding ‘#line’ directive, (see Line Control), except that trailing flags are permitted, and are interpreted with the meanings described above. If multiple flags are given, they must be in ascending order.

Some directives may be duplicated in the output of the preprocessor. These are ‘#ident’ (always), ‘#pragma’ (only if the preprocessor does not handle the pragma itself), and ‘#define’ and ‘#undef’ (with certain debugging options). If this happens, the ‘#’ of the directive will always be in the first column, and there will be no space between the ‘#’ and the directive name. If macro expansion happens to generate tokens which might be mistaken for a duplicated directive, a space will be inserted between the ‘#’ and the directive name.

引自:https://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值