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.
format function attribute syntax .-,--------------------------------------------------------------------------. V | >>-__attribute__--((----+-format-----+--(--+-printf-------+--,--string_index--,--first_to_check--)-+--))->< '-__format__-' +-scanf--------+ +-strftime-----+ +-strfmon------+ +-__printf__---+ +-__scanf__----+ +-__strftime__-+ '-__strfmon__--'
where
It is possible to specify multiple format attributes on the same function, in which case, all apply.
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)));