Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

__printf_args pragma

&pagelevel(4)&pagelevel

This pragma can be used for additional parameter checks. As an example:


#pragma __printf_args

void my_printf(int arg1, const char *format, ...);

void foo()

{

  my_printf(5, "falsches Argument %s\n", 42);

}


The pragma must be placed directly in front of a function declaration. This function is then assumed to be like printf. It has to have a variable number of arguments. The last argument before the ellipsis is assumed to be a format string. That format string has the same semantics as in the function printf.

When a call to that function has a string literal as format string, the remaining arguments are checked against the conversion specifiers in the format string. Any mismatch is reported with a message.

The weight of the message depends on the kind of difference. When the execution of the function call only leads to strange output, the difference is marked with a warning. An example would be a floating point number for %d. A note is issued when int is mixed with unsigned int or long.
An error is issued when the execution leads to other problems. When the size of the conversion specifier and argument is different, none of the following arguments is output correctly. An error is also issued when the format specifier expects a pointer but a number was used as argument.

The example will give an error. The conversion specifier %s expects a char *, but the argument has type int.

This check is also done for the CRTE functions printf, fprintf, sprintf and snprintf.