这个C代码是什么意思(G_GNUC_PRINTF)?

这个C代码是什么意思(G_GNUC_PRINTF)?,第1张

概述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): #defin
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:

Expands to the GNU C format function attribute if the compiler is gcc. This is used for declaring functions which take a variable number of arguments,with the same Syntax as printf(). It allows the compiler to type-check the arguments passed to the function.

Place the attribute after the function declaration,just before the semicolon.

Parameters:

format_IDx: the index of the argument corresponding to the format string (The arguments are numbered from 1)

arg_IDx: the index of the first of the format arguments

例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 ----------------+            <-------+

摘要:

Is there just one function declaration or two ?

一个类似printf()的函数被定义.宏告诉编译器对传递给函数的参数进行类型检查.

总结

以上是内存溢出为你收集整理的这个C代码是什么意思(G_GNUC_PRINTF)?全部内容,希望文章能够帮你解决这个C代码是什么意思(G_GNUC_PRINTF)?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1218418.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存