gcc 中已经定义了哪些 C 预处理器宏?
在 gcc
中,如何检查 C 程序编译期间存在哪些 C 预处理器定义,特别是定义了哪些标准或特定于平台的宏定义?
In gcc
, how can I check what C preprocessor definitions are in place during the compilation of a C program, in particular what standard or platform-specific macro definitions are defined?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
预定义的宏取决于标准和编译器实现它的方式。
对于 GCC: http://gcc.gnu.org/onlinedocs/cpp/Predefined- Macros.html
对于 Microsoft Visual Studio 8:http ://msdn.microsoft.com/en-us/library/b0084kay(VS.80).aspx
此维基百科页面 http://en.wikipedia.org/wiki/C_preprocessor#Compiler-specific_predefined_macros 列出了如何转储一些预定义的宏
Predefined macros depend on the standard and the way the compiler implements it.
For GCC: http://gcc.gnu.org/onlinedocs/cpp/Predefined-Macros.html
For Microsoft Visual Studio 8: http://msdn.microsoft.com/en-us/library/b0084kay(VS.80).aspx
This Wikipedia page http://en.wikipedia.org/wiki/C_preprocessor#Compiler-specific_predefined_macros lists how to dump at some of the predefined macros
特定编译器和平台组合的预定义宏的可能来源是 Sourceforge 的 Predef 项目。 他们试图在所有平台上的所有 C 和 C++ 编译器中维护所有预定义宏的目录。 在实践中,他们覆盖了相当多的 GCC 平台和少数其他编译器。
他们通过仔细阅读文档以及 shell 脚本来实现这一目标,该脚本以困难的方式找出预定义的宏:尝试它们。 我的理解是,它实际上会尝试在编译器和/或预处理器的可执行映像中找到的每个字符串,以查看它是否具有预定义的含义。
他们会很乐意将尚未拥有的任何信息添加到数据库中。
A likely source of the predefined macros for a specific combination of compiler and platform is the Predef project at Sourceforge. They are attempting to maintain a catalog of all predefined macros in all C and C++ compilers on all platforms. In practice, they have coverage of a fair number of platforms for GCC, and a smattering of other compilers.
They achieved this through a combination of careful reading of documentation, as well as a shell script that figures out what macros are predefined the hard way: it tries them. My understanding is that it actually tries every string it can find in the executable image of the compiler and/or preprocessor to see if it has a predefined meaning.
They will happily add any info they don't have yet to their database.