The format function attribute provides a way to identify user-defined functions that take format strings as arguments so that calls to these functions will be type-checked against a format string, similar to the way the compiler checks calls to the functions printf, scanf, strftime, and strfmon for errors.
whereformat function attribute syntax .-,--------------------------------------------------------------------------. V | >>-__attribute__--((----+-format-----+--(--+-printf-------+--,--string_index--,--first_to_check--)-+--))->< '-__format__-' +-scanf--------+ +-strftime-----+ +-strfmon------+ +-__printf__---+ +-__scanf__----+ +-__strftime__-+ '-__strfmon__--'
In
C++, the minimum value of string_index for nonstatic member
functions is 2 because the first argument is an implicit this argument.
This behavior is consistent with that of GNU C++.void my_fn(const char* a, const char* b, ...)
__attribute__((__format__(__printf__,1,0), __format__(__scanf__,2,3)));
It
is also possible to diagnose the same string for different format
styles. All styles are diagnosed. void my_fn(const char* a, const char* b, ...)
__attribute__((__format__(__printf__,2,3),
__format__(__strftime__,2,0),
__format__(__scanf__,2,3)));