Freigeben über


C6328

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 C6328: Size mismatch: <type> passed as parameter <number> when <type> is required in call to <function>

For C runtime character-based routines in the family name isxxx(), passing an argument of type char can have unpredictable results. For example, an SBCS or MBCS single-byte character of type char with a value greater than 0x7F is a negative value. If a char is passed, the compiler might convert the value to a signed int or a signed long. This value could be sign-extended by the compiler, with unexpected results. For example, isspace accepts an argument of type int; however, the valid range of values for its input argument is:

0 <= c <= 255, plus the special value EOF.

Example

By default, char is a signed type in Visual C++, so the range of values of a variable of type char is -128 <= c <= 127. Therefore, if you did the following:

#include <iostream>  
  
void f( )  
{  
    char c = -37;  
    int retVal = isspace( c );  
    // code ...  
}  
  

c would be sign-extended to a signed int with a value of -37, which is outside the valid range for isspace.

To correct this problem, you can use static_cast, as shown in the following code:

#include <iostream>  
  
void f( )  
{  
    char c = -37;  
    int retVal = isspace( static_cast<unsigned char> (c) );  
    // code ...  
}  
  

Warning C6328 exists specifically to catch this bug. For characters in the 7-bit ASCII range the cast is unnecessary, but characters outside that range can have unpredictable results, up to and including program fault and termination.