Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function definition(?) without {}

Tags:

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.

like image 202
vericule Avatar asked Apr 30 '13 09:04

vericule


People also ask

Which function has no definition in C++?

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(); .

How do you define a function?

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. 🔗

What is the def function in Python?

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.

Do you have to define function before calling it Python?

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.


1 Answers

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.

like image 91
interjay Avatar answered Sep 24 '22 23:09

interjay