Reading Notes 1 -- Unicode
Unicode is not required for wide bytes. unicode is a possible wide character encoding. ansi c also supports multi-byte character sets. the width character in C is based on the wchar_t data type typedef unsigned short wchar_t (unsigned short integer, 16-Bit Width) wchar_t * P = l "hello "; static wchar_t A [] = l "hello"; L stands for long
Wchar_t c = L 'a ';
Here l is usually unnecessary. The compiler will perform zero expansion on this character anyway.
When calculating the string length, the wide byte version function corresponding to strlen (const char *) is wcslen (const wchar_t *)
- Maintain single source code
A series of macros are maintained for a single one that can be compiled by ASCII and can be compiled by Unicode.CodeFile.
Tchar. the H header file defines the following macro: If _ Unicode identifier typedef wchar_t tchar is defined, and the opposite is typedef char tchar # DEFINE _ T (x) L # X # DEFINE _ T (X) _ T (X)
# DEFINE _ text (x) _ T (X)
Use the _ T (x) macro to define the string text. According to the _ Unicode identifier, the string is interpreted as a combination of wide characters or 8-bit characters, for example, strlen (const char *) when calculating the string length in the C runtime, and wcslen (const wchar_t *) Windows string functions are: int lstrlen (
Lpctstr
Lpstring
); The definition of lpctstr is WINBASE. in H # ifdef Unicode // r_winnt # ifndef _ tchar_definedtypedef wchar tchar, * ptchar; typedef wchar tbyte, * ptbyte; # DEFINE _ tchar_defined # endif /*! _ Optional */typedef lpwch lptch, ptch; typedef lpwstr ptstr, lptstr; typedef lpcwstr pctstr, lpctstr; typedef extends putstr, lputstr; typedef extends pcutstr, lpcutstr; typedef lpwstr LP; # DEFINE _ text (quote) L # quote // r_winnt # else/* Unicode * // r_winnt # ifndef _ tchar_definedtypedef char tchar, * ptchar; typedef unsigned char tbyte, * ptbyte; # DEFINE _ tchar_defined # endif /*! _ Tchar_defined */typedef lpch lptch, ptch; typedef lpstr ptstr, lptstr, putstr, lputstr; typedef lpcstr pctstr, lpctstr, pcutstr, and lpcutstr; # DEFINE _ text (quote) quote // r_winnt # endif/* Unicode * // r_winnt # define text (quote) _ text (quote) // r_winnt