Warning C6272
Non-float passed as argument 'number' when float is required in call to 'function-name'
Remarks
This warning indicates that the format string specifies that a float is required. For example, a %f
or %g
specification for printf
, but a non-float such as an integer or string is being passed. This defect can lead to crashes, in addition to potentially incorrect output.
Code analysis name: NON_FLOAT_ARGUMENT_TO_FORMAT_FUNCTION
Example
The following code generates this warning. %f
indicates a float is expected, but the integer i
is passed instead:
void f()
{
char buff[5];
int i=5;
sprintf_s(buff, sizeof(buff), "%s %f", "a", i);
}
To correct this warning, change the format specifier or modify the parameters passed to the function. In this example, we correct this warning by using %i
instead of %f
.
void f()
{
char buff[5];
int i=5;
sprintf_s(buff, sizeof(buff), "%s %i", "a", i);
}
See also
Format specification syntax: printf and wprintf functions
sprintf
, _sprintf_l
, swprintf
, _swprintf_l
, __swprintf_l
sprintf_s
, _sprintf_s_l
, swprintf_s
, _swprintf_s_l
C4477