Reading Notes 1-Unicode

Source: Internet
Author: User

Reading Notes 1 -- Unicode

    • Wide Section
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

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.