【问题标题】:Function definition(?) without {}没有 {} 的函数定义(?)
【发布时间】:2013-04-24 03:40:03
【问题描述】:

我正在阅读avio.h(ffmpeg 的一部分),并且有这样的定义(?):

int avio_printf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3);

我不明白。有人可以解释一下这是做什么的吗?谢谢。

【问题讨论】:

    标签: c ffmpeg


    【解决方案1】:

    av_printf_format 是一个宏,可以选择在函数声明中添加 GCC 属性。它被定义为in attributes.h:

    #ifdef __GNUC__
    #    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
    

    所以这实际上是一个函数声明,如果在 GCC 上编译,它可能具有特定的属性。

    format 属性告诉 GCC,该函数接受它的参数,如 printf,这有助于诊断一些错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-20
      • 1970-01-01
      • 2012-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多