다음을 통해 공유


C6066

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

warning C6066: non-pointer passed as parameter <number> when pointer is required in call to <function>

This warning indicates that the format string specifies that a pointer is required, for example, a %n or %p specification for printf or a %d for scanf, but a non-pointer is being passed. This defect is likely to cause a crash or corruption of some form.

Example

The following code generates this warning:

#include <stdio.h>  
#define MAX 30  
void f( )  
{  
  char buff[MAX];  
  sprintf( buff, "%s %p %d", "Hello, World!", 1, MAX ); //warning C6066  
  // code ...  
}  
  
void g( int i )  
{  
   int   result;  
   result = scanf( "%d", i ); // warning C6066  
   // code ...  
}  

To correct this warning, the following code passes correct parameters to the sprintf and scanf functions:

#include <stdio.h>  
#define MAX 30  
  
void f( )  
{  
   char buff[MAX];  
  
   sprintf( buff, "%s %p %d", "Hello, World!", buff, MAX ); // pass buff  
   // code ...   
}  
void g( int i )  
{  
   int   result;  
   // code ...  
   result = scanf( "%d", &i ); // pass the address of i  
   // code ...  
}  

The following code use safe string manipulation functions — sprintf_s and scanf_s — to correct this warning:

void f( )  
{  
   char buff[MAX];  
  
   sprintf_s( buff, sizeof(buff), "%s %p %d", "Hello, World!", buff, MAX );   
   // code ...   
}  
void g( int i )  
{  
   int result;  
   // code ...  
   result = scanf_s( "%d", &i );   
   // code ...  
}  

This warning is typically reported because an integer has been used for a %p format instead of a pointer. Using an integer in this instance is not portable to 64-bit computers.

See Also

sprintf_s, _sprintf_s_l, swprintf_s, _swprintf_s_l
scanf_s, _scanf_s_l, wscanf_s, _wscanf_s_l