在编译 C 代码期间我可以看到定义的宏吗?
我有一段代码,在 x86 gcc 4.4.1 上编译没有问题,但在 blackfin gcc 4.1.2 上编译失败,并出现许多“在数字常量之前预期的不合格 id”错误。我发现有些变量名称与某些预定义的宏发生冲突。是否可以在 cpp 文件的某一行看到定义的宏?
I have a piece of code which compiles without problems with x86 gcc 4.4.1 but fails with blackfin gcc 4.1.2 with many "expected unqualified-id before numeric constant" errors. I see that there are some variable names that clash with some predefined macros. Is it possible to see defined macros at a certain line of a cpp file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
-dM
开关告诉 GCC 转储给定文件中定义的所有宏(它将包括语言标准所需定义的宏列表以及 GCC 定义的任何其他宏)-E
开关告诉 GCC 在预处理文件后不要继续编译。为了查看 cpp 文件的给定行定义的宏列表,首先过滤掉任何预定义的宏(由编译器定义的宏)可能会更容易。在 BASH 中,您可以这样做:
这应该过滤掉标准系统标头或框架定义的任何宏。额外的部分
-x c++
告诉 GCC 将输入解释为 C++ 源代码[需要预处理],这是因为它无法根据文件名的扩展名来确定它(源代码通过 stdin 交给 GCC)。The
-dM
switch tells GCC to dump all the macros defined in the given file (it will include a list of macros required to be defined by the language standard as well as any additional macros GCC defines itself).The
-E
switch tells GCC not to continue compiling after it has preprocessed the file.In order to see a list of macros defined at a given line of a cpp file, it may be easier to first filter out any of the predefined macros (macros defined by the compiler). In BASH, you could do:
This should filter out any macros defined by standard system headers or frameworks. The extra part,
-x c++
, tells GCC to interpret the input as C++ source [that requires preprocessing], this is because the it won't be able to determine it based on the extension of the filename (the source code is handed to GCC via stdin).