dbus 매크로 정의 해석

dbus-macro.h에 이런 코드가 있다#ifGNUC__ > 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
string_index
Is a constant integral expression that specifies which argument in the declaration of the user function is the format string argument.   In C++, the minimum value of 
string_index for nonstatic member functions is 2 because the first argument is an implicit  this argument. This behavior is consistent with that of GNU C++.
first_to_check
Is a constant integral expression that specifies the first argument to check against the format string. If there are no arguments to check against the format string (that is, diagnostics should only be performed on the format string syntax and semantics), 
first_to_check should have a value of  0. For  strftime-style formats, 
first_to_check is required to be  0.
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

좋은 웹페이지 즐겨찾기