av_printf_format

1. av_printf_format 是一个函数属性宏(format属性),定义在attributes.h文件中。

#if defined(__GNUC__) || defined(__clang__)
#    define av_builtin_constant_p __builtin_constant_p
#    define av_printf_format(fmtpos, attrpos) __attribute__((__format__(__printf__, fmtpos, attrpos)))
#else
#    define av_builtin_constant_p(x) 0
#    define av_printf_format(fmtpos, attrpos)
#endif

2. format方法格式:format (archetype, string-index, first-to-check)

format 属性指定一个函数的参数风格与printf/scanf/strfting/strfmon的风格一样,这些参数需要根据格式化字符串进行检测。

  1.  archetype:指定怎样解析函数的格式化字符串,它的值为printfscanfstrftimegnu_printfgnu_scanfgnu_strftime or strfmon.
  2. string-index:指定函数的第几个参数是格式化字符串。
  3. first-to-check:指定从函数的第几个参数开始按照格式化串进行类型检测。

3.示例

static av_printf_format(3, 4) void url_add_option(char *buf, int buf_size, const char *fmt, ...)

//url_add_option的格式化字符串的解析按printf的标准进行。
//url_add_option的第3个参数,即fmt,是格式化字符串。
//编译器需要从url_add_option的第四个参数开始按fmt进行类型检测。

  4. 参考

Using the GNU Compiler Collection (GCC)

https://gcc.gnu.org/onlinedocs/gcc/index.html#SEC_Contents

6.33.1 Common Function Attributes

https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值