Define RCUTILS_ATTRIBUTE_PRINTF_FORMAT

Define Documentation

RCUTILS_ATTRIBUTE_PRINTF_FORMAT(format_string_index, first_to_check_index)

Macro to annotate printf-like functions which are relying on a format string and a variable number of arguments. This enables GCC to emit warnings if dangerous patterns are detected. See GCC documentation for details: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html

For the following function:

int snprintf(char *str, size_t size, const char *format, ...);
             ^^^^^^^^^  ^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^  ^^^
             ARG 1      ARG 2        ARG 3               ARG 4
                                     format string       first optional argument
format_string_index value would be 3, first_to_check_index value would be 4.

IMPORTANT: the first argument has an index of ONE (not zero!).

Parameters:
  • format_string_index[in] index of the format string passed to the function

  • first_to_check_index[in] index of the first “optional argument”