【发布时间】:2014-04-09 09:40:39
【问题描述】:
GCC 版本 ntoarm-gcc (GCC) 4.4.2
我已经为包装 printf() 和 co 的所有函数添加了“printf”格式属性。除了使用可变参数宏调用函数时,它们工作得很好。
class Log { [...]
void log_fmt(LogLevel level, const std::string& funcName, const char_t * const logFormatStr, ...) __attribute__ ((format (printf, 4, 5)));
[...] };
不正确的直接调用,例如
log.log_fmt(Info, "test", "wrong %u", "type");
产生警告:
format '%u' expects type 'unsigned int', but argument 5 has type 'const char*'
但是,使用宏的相同错误调用不会产生警告:
#define LOGI(MSG, ...) log.log_fmt(Info, __func__, (MSG), __VA_ARGS__)
LOGI("wrong %u", "type");
在这种情况下我也可以显示警告吗?我犯了错误还是这是故意的行为?
【问题讨论】:
-
宏不检查类型。它们只是重复
-
你试过
-Wall和-Wextra参数改成gcc