Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

C6273

Warning 6273 - non-integer passed as parameter <number> when integer is required in call to <function>: if a pointer value is being passed, %p should be used

This warning indicates that the format string specifies an integer, for example, a %d, length or precedence specification for printf but a non-integer such as a float, string, or struct is being passed as a parameter. This defect is likely to result in incorrect output.

The following code generates this warning because an integer is required instead of a float to sprintf function:

#include <stdio.h>
#include <string.h>

void f_defective()
{
  char buff[50];
  float f=1.5;
  
  sprintf(buff, "%d",f);
}

The following code uses an integer cast to correct this warning:

#include <stdio.h>
#include <string.h>

void f_corrected()
{
  char buff[50];
  float f=1.5;

  sprintf(buff,"%d",(int)f);
}

The following code uses safe string manipulation function, sprintf_s, to correct this warning:

#include <stdio.h>
#include <string.h>

void f_safe()
{
  char buff[50];
  float f=1.5;

  sprintf_s(buff,50,"%d",(int)f);
}

This warning is not applicable on Windows 9x and Windows NT version 4 because %p is not supported on these platforms.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.