Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
C6328
Collapse the table of content
Expand the table of content

C6328

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.

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.

Show:
© 2015 Microsoft