C/C++编译器列出定义的内容
这个问题: 有没有办法判断代码现在是否被编译为 PCH 的一部分? 引导我思考这个问题。
有没有办法,也许只有某些编译器,让 C/C++ 编译器转储它当前正在使用的定义?
编辑:我知道这在技术上是一个预处理器问题,但让我们将其添加到术语编译器中。
This question : Is there a way to tell whether code is now being compiled as part of a PCH? lead me to thinking about this.
Is there a way, in perhaps only certain compilers, of getting a C/C++ compiler to dump out the defines that it's currently using?
Edit: I know this is technically a pre-processor issue but let's add that within the term compiler.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。在 GCC 中,
我敢打赌几乎在所有编译器中都是可能的。
Yes. In GCC
I would bet it is possible in nearly all compilers.
Boost Wave(一个恰好包含命令行驱动程序的预处理器库)包含 跟踪能力来跟踪宏扩展。它可能比您要求的要多一点——它不仅显示最终结果,而且基本上显示扩展宏的每一步(即使是非常复杂的步骤)。
clang 预处理器有点类似。它基本上也是一个恰好包含命令行驱动程序的库。预处理器定义
macro_iterator
类型和这种类型的 Macro_begin
/macro_end
可以让您遍历预处理器符号表并用它做几乎任何您想做的事情(当然包括打印出符号)。Boost Wave (a preprocessor library that happens to include a command line driver) includes a tracing capability to trace macro expansions. It's probably a bit more than you're asking for though -- it doesn't just display the final result, but essentially every step of expanding a macro (even a very complex one).
The clang preprocessor is somewhat similar. It's also basically a library that happens to include a command line driver. The preprocessor defines a
macro_iterator
type andmacro_begin
/macro_end
of that type, that will let you walk the preprocessor symbol table and do pretty much whatever you want with it (including printing out the symbols, of course).