Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

__scanf_args pragma

&pagelevel(4)&pagelevel

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


#pragma __scanf_args

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

void foo()

{

  int i;

  my_scanf(5, "wrong argument %d\n", i);

}


The pragma must be placed directly in front of a function declaration. This function is then assumed to be like scanf. 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 scanf.

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.

An error is issued when the size of the conversion specifier and argument is different. In such a case either the variable would be written only partly, or the bytes after the variable are changed. An error is also issued when the argument is not a pointer.

Other differences give a warning or note.

The example will give an error. The conversion specifier %d expects a int *, but the argument has type int. The call is missing an address operator &.

This check is also done for the CRTE functions scanf, fscanf and sscanf.