【发布时间】:2018-08-26 01:43:16
【问题描述】:
编译时,我在 .h 文件中的 3 行不同的代码上收到相同的警告,例如:
警告
gnu_printf是无法识别的格式函数类型
我的标志是这样的:
CFLAGS += -Wall -Wextra -Wformat -Wno-ignored-qualifiers -Wformat-security -Wno-unused-parameter \
下面产生此错误的三行代码示例:
int ATTR_WARN_PRINTF(1,2) OutputDebugStringF(const char* pszFormat, ...);
std::string ATTR_WARN_PRINTF(1,3) real_strprintf(const char *format, int dummy, ...);
bool ATTR_WARN_PRINTF(1,2) error(const char *format, ...);
我在这个文件中有许多其他的printf() 用法,它们没有产生任何错误。我对格式错误有点困惑。
【问题讨论】:
-
什么是
ATTR_WARN_PRINTF()? -
@Azeem
/* This GNU C extension enables the compiler to check the format string against the parameters provided. * X is the number of the "format string" parameter, and Y is the number of the first variadic parameter. * Parameters count from 1. */ #ifdef __GNUC__ #define ATTR_WARN_PRINTF(X,Y) __attribute__((format(gnu_printf,X,Y))) #else #define ATTR_WARN_PRINTF(X,Y) #endif -
对。您能否发布一个导致此警告的最小代码示例?一个可以单独编译的。谢谢。
-
您可以查看第 172-198 行以查看错误的来源。 link
-
你用的是什么编译器?铛? MinGW 上的东西?什么版本?
标签: c++ printf compiler-warnings