【发布时间】:2019-10-29 04:58:16
【问题描述】:
我最近发现如果文件结尾是 .i 或 .ii,gcc 会跳过预处理,并决定试一试。编译一个不包含 stdio.h 的 hello world 程序:
gcc -Wall file.c; # compiles with preprocessor, implicit declaration of puts
gcc -Wall file.i; # compiles without preprocessor, implicit declaration of puts
如果没有预处理器指令,我不能包含 stdio.h,但我记得 gcc 的 -include 标志可用于“强制包含”标头。它导致了以下测试:
gcc -Wall -include stdio.h file.c; # no warnings, "hello world". hooray
gcc -Wall -include stdio.h file.i; # implicit declaration of puts WAIT WHAT?!
如果在没有预处理的情况下编译文件,我觉得 gcc 不包含 stdio.h 很奇怪。更奇怪的是如何没有发出警告; -include stdio.h 没有明显效果,充其量是gcc的错误使用。
为什么它不起作用?
GCC 版本 6.3.0。
【问题讨论】:
-
-E选项生成预处理文件,test.c生成test.i。因此,查看 .i 文件扩展名并将其用作不再运行预处理器的提示似乎是硬编码的。只需选择另一个扩展程序。
标签: c gcc preprocessor