Warning C6328

Size mismatch: 'type' passed as Param(number) when 'type' is required in call to 'function-name'

Remarks

This warning indicates that type required by the format specifier and the type of the expression passed in don't match. Using the wrong format specifier is undefined behavior. To fix the warning, make sure that the format specifiers match the types of the expressions passed in.

Code analysis name: FORMAT_SIZE_MISMATCH

Example

#include <cstdio>

void f(long long a)
{
    printf("%d\n", a); // C6328 emitted.
}

There are multiple ways to fix the undefined behavior. We can change the format specifier:

#include <cstdio>

void f(long long a)
{
    printf("%lld\n", a); // No C6328 emitted.
}

We can change the type of the expression:

#include <cstdio>

void f(int a)
{
    printf("%d\n", a); // No C6328 emitted.
}

As a last resort when overflow can't happen, we can introduce a cast:

#include <cstdio>

void f(unsigned char a)
{
    printf("%hhd\n", static_cast<signed char>(a)); // No C6328 emitted.
}

See also

C6340