17.2.9 Format Function Attribute

The format (type, format_index, first_to_check) attribute indicates that the function takes a printf, scanf, strftime, or strfmon style format string and arguments and that the compiler should type check those arguments against the format string, just as it does for the standard library functions, for example:
extern int __attribute__ ((format (printf, 2, 3))) my_printf (void *my_object, const char *my_format, ...);

The type parameter is one of printf, scanf, strftime or strfmon (optionally with surrounding double underscores, for example, __printf__) and determines how the format string will be interpreted.

The format_index parameter specifies which function parameter is the format string. Function parameters are numbered from the left-most parameter, starting from 1.

The first_to_check parameter specifies which parameter is the first to check against the format string. If first_to_check is zero, type checking is not performed and the compiler only checks the format string for consistency (for example, vfprintf).