SBCS and MBCS Data Types
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at SBCS and MBCS Data Types.
Any Microsoft MBCS run-time library routine that handles only one multibyte character or one byte of a multibyte character expects an unsigned``int argument (where 0x00 <= character value <= 0xFFFF and 0x00 <= byte value <= 0xFF ). An MBCS routine that handles multibyte bytes or characters in a string context expects a multibyte-character string to be represented as an unsigned``char pointer.
Each byte of a multibyte character can be represented in an 8-bit |
Therefore it is best to represent a byte of a multibyte character as an 8-bit unsigned char. Or, to avoid a negative result, simply convert a single-byte character of type char to an unsigned char before converting it to an int or a long.
Because some SBCS string-handling functions take (signed) char* parameters, a type mismatch compiler warning will result when _MBCS is defined. There are three ways to avoid this warning, listed in order of efficiency:
Use the "type-safe" inline functions in TCHAR.H. This is the default behavior.
Use the "direct" macros in TCHAR.H by defining
_MB_MAP_DIRECTon the command line. If you do this, you must manually match types. This is the fastest method but is not type-safe.Use the "type-safe" statically linked library functions in TCHAR.H. To do so, define the constant
_NO_INLININGon the command line. This is the slowest method, but the most type-safe.