The format_arg function attribute

The format_arg function attribute provides a way to identify user-defined functions that modify format strings. Once the function is identified, calls to functions like printf, scanf, strftime, or strfmon, whose operands are a call to the user-defined function can be checked for errors.

Read syntax diagramSkip visual syntax diagramformat_arg function attribute syntax

where string_index is a constant integral expression that specifies which argument is the format string argument, starting from 1. C++ only For non-static member functions in C++, string_index starts from 2 because the first parameter is an implicit this parameter.

It is possible to specify multiple format_arg attributes on the same function, in which case, all apply.

extern char* my_dgettext(const char* my_format, const char* my_format2) 
          __attribute__((__format_arg__(1))) __attribute__((__format_arg__(2))); 

//printf-style format diagnostics are performed on both "%" strings