假设我有一个带有许多预处理器指令的源文件。是否有可能看到它在预处理器完成后的样子?
当前回答
CPIP是一个新的C/ c++预处理器,用Python编写。如果您想要预处理文件的详细可视化表示,可以尝试一下。
CPIP is a C/C++ pre-processor implemented in Python. Most pre-processors regard pre-processing as a dirty job that just has to be done as soon as possible. This can make it very hard to track down subtle defects at the pre-processing stage as pre-processors throw away a lot of useful information in favor of getting the result as cheaply as possible. Few developers really understand pre-processing, to many it is an obscure bit of black magic. CPIP aims to improve that and by recording every detail of preprocessing so CPIP can can produce some wonderfully visual information about file dependencies, macro usage and so on. CPIP is not designed to be a replacement for cpp (or any other established pre-processor), instead CPIP regards clarity and understanding as more important than speed of processing.
其他回答
大多数编译器都有只运行预处理器的选项。例如,gcc提供-E:
-E Stop after the preprocessing stage; do not run the compiler proper.
The output is in the form of preprocessed source code, which is sent
to the standard output.
所以你可以运行:
gcc -E foo.c
如果你找不到这样的选项,你也可以在你的机器上找到C预处理器。它通常被称为cpp,可能已经在您的路径中。像这样调用它:
cpp foo.c
如果需要包含来自其他目录的头文件,可以将-I/path/to/include/dir传递给其中任何一个,就像使用常规编译一样。
对于Windows,我将把它留给其他人来提供答案,因为我不是这方面的专家。
CPIP是一个新的C/ c++预处理器,用Python编写。如果您想要预处理文件的详细可视化表示,可以尝试一下。
CPIP is a C/C++ pre-processor implemented in Python. Most pre-processors regard pre-processing as a dirty job that just has to be done as soon as possible. This can make it very hard to track down subtle defects at the pre-processing stage as pre-processors throw away a lot of useful information in favor of getting the result as cheaply as possible. Few developers really understand pre-processing, to many it is an obscure bit of black magic. CPIP aims to improve that and by recording every detail of preprocessing so CPIP can can produce some wonderfully visual information about file dependencies, macro usage and so on. CPIP is not designed to be a replacement for cpp (or any other established pre-processor), instead CPIP regards clarity and understanding as more important than speed of processing.
在解决方案资源管理器上右键单击该文件,转到属性。在配置属性->C/ c++ ->预处理器下,“生成预处理文件”就是你要找的。然后在解决方案资源管理器中右键单击该文件并选择“编译”。预处理文件在输出目录(例如Release, Debug)中创建,扩展名为.i(感谢Steed的评论)。
我对微软编译器一无所知,但在GCC上你可以使用这个:
gcc -E -P -o result.c my_file.h
如果你想看到注释,使用这个:
gcc -E -C -P -o result.c my_file.h
本页有更多选项。
如果您正在使用微软的c++编译器,请尝试cl /EP。
推荐文章
- C多行宏:do/while(0) vs作用域块
- 找出质数最快的算法是什么?
- 我如何调试git/git-shell相关的问题?
- time_t最终的类型定义是什么?
- 我需要显式处理负数或零时,总和平方数字?
- c++枚举类可以有方法吗?
- 函数名周围的括号是什么意思?
- 用C语言创建自己的头文件
- Visual Studio拒绝忘记断点?
- 格式化IO函数(*printf / *scanf)中的转换说明符%i和%d之间的区别是什么?
- 将析构函数设为私有有什么用?
- main()中的Return语句vs exit()
- 为什么c#不提供c++风格的'friend'关键字?
- 如果不是内存地址,C指针到底是什么?
- 如何在Python自己的调试器(PDB)中执行多行语句