Udostępnij za pośrednictwem


C6400

warning C6400: Using <function name> to perform a case-insensitive compare to constant string <string name>. Yields unexpected results in non-English locales

This warning indicates that a case-insensitive comparison to a constant string is being performed in a locale-dependent way, when, apparently, a locale-independent comparison was intended.

The typical consequence of this defect is incorrect behavior in non-English speaking locales. For example, in Turkish, ".gif" will not match ".GIF"; in Vietnamese, "LogIn" will not match "LOGIN".

String comparisons should typically be performed with the CompareString function. To perform a locale-independent comparison on Windows XP, the first parameter should be the constant LOCALE_INVARIANT.

Example

The following code generates this warning:

#include <windows.h>
int f(char *ext)
{
  // code...
  return (lstrcmpi(ext, TEXT("gif")) == 0);
}

To correct this warning, perform a locale-independent test for whether char *ext matches "gif" ignoring upper/lower case differences, use the following code:

#include <windows.h>
int f(char *ext)
{
  // code...
  return (CompareString(
                        LOCALE_INVARIANT,
                        NORM_IGNORECASE, 
                        ext,
                        -1,
                        TEXT ("gif"),
                        -1) == CSTR_EQUAL);
}

See Also

Reference

CompareString