这个C代码是什么意思(G_GNUC_PRINTF)?
static void ddict_debug(const char* fmt,...) G_GNUC_PRINTF(1,2); 我在.c文件中发现了这个,我不明白这一行: 这段代码是什么意思? 解决方法
G_GNUC_PRINTF()是一个glib库预处理器宏.
对于gcc编译器,它定义如下(来自glib-2.4.5 / glib / gmacros.h): #define G_GNUC_PRINTF( format_idx,arg_idx ) __attribute__((__format__ (__printf__,format_idx,arg_idx))) 从gnome documentation:
例1: static void ddict_debug(const char* fmt,2); // | | | | // format string,format_idx = 1 ----+ | <----+ | // format arguments,arg_idx = 2 ---------+ <-------+ 例2: static void foo_debug(int foo,const char* fmt,...) G_GNUC_PRINTF(2,3); // | | | | | // not a printf argument --+ | | | | // format string,format_idx = 2 -----------+ | <----+ | // format arguments,arg_idx = 3 ----------------+ <-------+ 摘要:
一个类似printf()的函数被定义.宏告诉编译器对传递给函数的参数进行类型检查. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |