close

http://zh.wikipedia.org/zh-hant/%E5%AF%AC%E5%AD%97%E5%85%83




寬字元(Wide character) 是程式設計的術語。它是一個含糊的術語,用以表示比 8 位元字元還寬的資料類型。它不同於Unicode

wchar_t 在 ANSI/ISO C中是一個資料類型,且某些其它的程式語言也用它來表示寬字元。

Unicode 標準 4.0 中提到

"ANSI/ISO C leaves the semantics of the wide character set to the
specific implementation but requires that the characters from the portable C execution set correspond to their wide character equivalents by zero extension."

還有

wchar_t 的寬度屬於編譯器的特性,且可以小到 8 位元。所以程式若需要跨過所有 C 和 C++ 編譯器的可攜性,就不應使用 wchar_t 儲存 Unicode 文字。wchar_t 類型是為儲存編譯器定義的寬字元,在部分編譯器中,其可以是 Unicode 字元。」

Windows API 中,wchar_t 是 16 位元寬。Windows API 因不使 wchar_t 字元類型在單一 wchar_t 單元中,支援所有系統可表示的字元,而破壞了 ANSI/ISO C 標準。wchar_t 在 Windows 下,反而表示一個 UTF-16 字元(或 UTF-16 的一部分)。

在類Unix系統中,wchar_t 是 32 位元寬。

ANSI C 程式庫表頭檔中,<wchar.h> 和 <wctype.h> 處理寬字元。


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 UbuntuLinux 的頭像
    UbuntuLinux

    UbuntuLinux

    UbuntuLinux 發表在 痞客邦 留言(0) 人氣()