Compiler Warning (level 1) C4477

'function' : format string 'string' requires an argument of type 'type', but variadic argument number has type 'type'

The compiler detected a mismatch between the type of argument required to satisfy the placeholder in a format string, and the type of argument supplied. Correct use of the printf and scanf families of variadic functions requires that you supply arguments of the types specified by the format string. 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

This sample shows two C4477 warnings for the first printf_s function, when two arguments are found to be of the wrong type, and also shows how to fix the issues.

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

void print_func(int a, float f)
{
    printf_s("This takes int and double arguments %d and %f.\n", f, a); // C4477, expected int then double
    printf_s("This takes int and double arguments %d and %f.\n", a, f); // fix: types in correct order
}

In the first error message, the compiler detects that a double argument is supplied when an int is expected. A float is automatically promoted to double in the variadic argument list. The second error message shows that the compiler expected a double argument, but an int was supplied. The compiler can't tell that you have swapped the order of the arguments. You must examine the format string to determine the actual argument order and supply the correct argument types.