Rus*_*ltz 7 c embedded gcc c-preprocessor preprocessor-directive
首先,我希望它停止警告.但我也希望打印出一些信息性的消息(比如"回来实现这个!").
不幸的是,我的编译器不支持#info,#message,#pragma message(),等.
我知道有-Wno-error=<something>,但我的谷歌-foo是弱,我似乎无法找出<something>的#warning.我试过了-Wno-error=warning,只是说"没有-Wwarning".与" warn" 相同.
有什么建议?
值得一提的是,我使用的是Tensilica xtensa编译器,xt-xcc,它似乎是一个gnu派生词,或者至少使用了gnu前端.它的版本是8.0.0.
如果您的编译器支持它,您可以尝试使用 constructor function 属性来定义一个在程序启动时(之前)运行的函数main,该函数将消息打印到 stdout:
#define TOKENPASTE(x, y) TOKENPASTE2(x, y)
#define TOKENPASTE2(x, y) x ## y
#define WARNING(message) \
static void TOKENPASTE(_print_warning, __LINE__)() __attribute__((constructor)); \
static void TOKENPASTE(_print_warning, __LINE__)() \
{ \
puts(message); \
}
WARNING("fix this before ship") // prints out a message at runtime before main
Run Code Online (Sandbox Code Playgroud)
这会导致在运行时而不是编译时打印一条消息,这几乎一样好,特别是如果您没有其他选择。唯一的限制是您必须在函数定义之外的全局范围内使用它。
| 归档时间: |
|
| 查看次数: |
5967 次 |
| 最近记录: |