Edit

Share via


Compiler Warning (level 1) C4473

'function' : not enough arguments passed for format string
placeholders and their parameters expect number variadic arguments, but number were provided
the missing variadic argument index is required by format string 'format_string'
this argument is used by a conversion specifier
this argument is used as a field width
this argument is used as a precision
this argument is used as a buffer size

The compiler detected a mismatch between the number of arguments required to satisfy the placeholders in a format string, and the number of arguments supplied. Correct use of the printf and scanf families of variadic functions requires that you supply as many arguments as specified by the format string. Certain placeholders require additional arguments, to specify the width, precision, or buffer size, as well as an argument for the content. A mismatch generally means there is a bug in your code.

For information on the arguments associated with printf family format string placeholders, see Format specification syntax: printf and wprintf functions. See the documentation for information specific to function function.

This warning is new in Visual Studio 2015.

Example

These samples show two ways warning C4473 can result from a format string mismatch with its arguments, and also show how to fix the issues.

// c4473p.cpp
// compile with: cl /c /W4 c4473p.cpp
#include <stdio.h>

void print_func(int a, float f)
{
    printf_s("This takes %*f arguments.\n", f); // C4473, missing * width argument
    printf_s("This takes %*f arguments.\n", a, f); // fix: supply width argument
}

In the first error message, the compiler detects that an argument is missing, but can't tell whether the missing argument is the width or the content, so it assumes the supplied argument is the first one, for the width, and the missing argument is the second one, for the type conversion specifier. You must examine the format string to determine the actual missing argument.

// c4473s.cpp
// compile with: cl /c /W4 c4473s.cpp
#include <stdio.h>

void scan_func(int a, float f)
{
    char name[20];

    scanf_s("%s", &name);                // C4473, missing buffer size argument
    scanf_s("%s", &name, sizeof(name));  // fix: supply buffer size argument
}

In this example, scanf_s requires two arguments for each placeholder, one to supply the address to write to, and a second to supply the size of the first. Check the documentation for each library function for an explanation of the required arguments.