Functions
Overview
A function is a reusable block of code that runs a particular task. A function reference without a following opening ( is converted to a pointer to its start. This conversion is called function decay.
Inlining
The inline qualifier is associated with a function definition. It suggests to the compiler that the qualified function may be inlined at callsites. Also,
- An
inlinefunction can be used in several TUs without causing a multiple-symbol-definition error. - All pointers to the same
inlinefunction will compare as equal, even if obtained in different TUs. - An
inlinefunction that is not used in a specific TU will be completely absent from the binary of that TU.
An inline function definition usually, but not necessarily, exists in a header file. An additional declaration without inline ensures emittance of the function symbol, though such a declaration can only exist in exactly one TU.
Interpositioning
Interpositioning refers to the supplanting of a library function with a user-written function of the same name.
Variadic Functions
The final parameter of a function may be .... Specifying this parameter produces a so-called variadic function. Before C23, the ... parameter required at least one other parameter before it. Since C23, this requirement is no longer in place.
When passed to a variadic parameter, arithmetic types are converted in the same manner as in arithmetic operations, with the exception of float arguments which are converted to double.
The <stdarg.h> header provides the va_list type used to represent the variadic argument list. It also provides a number of macros for traversing/manipulating the list.