I was reading avio.h (part of ffmpeg) and there is definition(?) like this:
int avio_printf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3);
.
I don't get it. Could someone explain me what this do? Thanks.
Since x() is never called, there's nothing to link so no error from linker that it's not defined. It's only declared as a function taking no arguments and returning an X : X x(); .
7.1 Definition of a Function A function has three parts, a set of inputs, a set of outputs, and a rule that relates the elements of the set of inputs to the elements of the set of outputs in such a way that each input is assigned exactly one output. 🔗
def is the keyword for defining a function. The function name is followed by parameter(s) in (). The colon : signals the start of the function body, which is marked by indentation. Inside the function body, the return statement determines the value to be returned.
All functions must be defined before any are used. However, the functions can be defined in any order, as long as all are defined before any executable code uses a function.
av_printf_format
is a macro, which can optionally add a GCC attribute to the function declaration. It's defined 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
So this is actually a function declaration, which may have a specific attribute if compiled on GCC.
The format
attribute tells GCC that the function takes its arguments like printf
, which helps diagnose some errors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With