dbus-macro.h里面有这样的代码
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)#define _DBUS_GNUC_PRINTF( format_idx, arg_idx ) \ __attribute__((__format__ (__printf__, format_idx, arg_idx)))#define _DBUS_GNUC_NORETURN \ __attribute__((__noreturn__))#else /* !__GNUC__ */#define _DBUS_GNUC_PRINTF( format_idx, arg_idx )#define _DBUS_GNUC_NORETURN#endif /* !__GNUC__ */对于这段代码的解释是
根据不同的gnuc的编译器版本,对printf的输入参数进行参数格式检查。
下面是对于部分代码的解释来源
GCC 中普通预定义宏
__GNUC__
__GNUC_MINOR__
__GNUC_PATCHLEVEL__
These macros are defined by all GNU compilers that use the C preprocessor: C, C++, and Objective-C. Their values are the major version, minor version, and patch level of the compiler, as integer constants. For example, GCC 3.2.1 will define __GNUC__ to 3, __GNUC_MINOR__ to 2, and __GNUC_PATCHLEVEL__ to 1. They are defined only when the entire compiler is in use; if you invoke the preprocessor directly, they are not defined.
__GNUC_PATCHLEVEL__ is new to GCC 3.0; it is also present in the widely-used development snapshots leading up to 3.0 (which identify themselves as GCC 2.96 or 2.97, depending on which snapshot you have).
来源:http://whitewang1614.blog.hexun.com/23166427_d.html
The format function attribute provides a way to identify user-defined functions that take format strings as arguments so that calls to these functions will be type-checked against a format string, similar to the way the compiler checks calls to the functions printf, scanf, strftime, and strfmon for errors.
format function attribute syntax .-,--------------------------------------------------------------------------. V | >>-__attribute__--((----+-format-----+--(--+-printf-------+--,--string_index--,--first_to_check--)-+--))->< '-__format__-' +-scanf--------+ +-strftime-----+ +-strfmon------+ +-__printf__---+ +-__scanf__----+ +-__strftime__-+ '-__strfmon__--'
where
It is possible to specify multiple format attributes on the same function, in which case, all apply.
void my_fn(const char* a, const char* b, ...) __attribute__((__format__(__printf__,1,0), __format__(__scanf__,2,3)));
It is also possible to diagnose the same string for different format styles. All styles are diagnosed.
void my_fn(const char* a, const char* b, ...) __attribute__((__format__(__printf__,2,3), __format__(__strftime__,2,0), __format__(__scanf__,2,3)));
来源:http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Ffn_attrib_format.htm