导读:
[讨论]关于 char ,w_char,_T( ),TCHAR,ACHAR 小结
鉴于 这几个 符号 容易搞混,现做一小总结,以抛砖引玉,
参考:
[1] 《Programming Windows》Chapter 2
[2] win 32 头文件 WCHAR.H TCHAR.H
[3] arx 2004 adesk.h
[4] arx 2007 头文件 adesk.h adaAChar.h
ps: 怕翻译不好,英文原版 引用 整理,以便大家更好理解经典。想了解的朋友请耐心看完,希望您有所收获
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>History of Character Sets (from Programming Windows)
●●The American Standard Code for Information Interchange (ASCII) had its origins in the late 1950s and was finalized in 1967.
●●The final code had 26 lowercase letters, 26 uppercase letters, 10 digits, 32 symbols, 33 control codes, and a space, for a total of 128 codes.
●●The basic problem we have here is that the world's written languages simply cannot be represented by 256 8-bit codes
●●Unicode is a uniform 16-bit system, thus allowing the representation of 65,536 characters. This is sufficient for all the characters and ideographs in all the written languages of the world, including a bunch of math, symbol, and dingbat collections.
●●ANSI C supports character sets that require more than one byte per character through a concept called "wide characters."
●●Wide characters aren't necessarily Unicode. Unicode is one possible wide-character encoding.
●●Wide characters in C are based on the wchar_t data type, which is defined in several header files, including WCHAR.H, like so:
typedef unsigned short wchar_t ;
To define a variable containing a single wide character, use the following statement:
wchar_t c = `A' ;
You can also define an initialized pointer to a wide-character string:
wchar_t * p = L"Hello!" ;
Similarly, you can define an array of wide characters this way:
static wchar_t a[] = L"Hello!" ;
The string again requires 14 bytes of storage, and sizeof (a) will return 14.
●●>>>>>>>>>>win32
TCHAR.H provides a set of alternative names for the normal run-time library functions requiring string parameters (for example, _tprintf and _tcslen). These are sometimes referred to as "generic"function names because they can refer to either the Unicode or non-Unicode versions of the functions.
TCHAR.H also solves the problem of the two character data types with a new data type named TCHAR.
If the _UNICODE identifier is defined, TCHAR is wchar_t:
typedef wchar_t TCHAR ;
Otherwise, TCHAR is simply a char:
typedef char TCHAR ;
If the _UNICODE identifier is defined, a macro called __T is defined like this:
#define __T(x) L##x
If the _UNICODE identifier is not defined, the __T macro is simply defined in the following way:
#define __T(x) x
●●>>>>>>>---- arx2004
在 adesk.h 中
// Continued use of the type "char" is prohibited. Please
// use only the abstract type "ACHAR" below, to contain
// character information.
typedef char ACHAR;
●●>>>>>>>------arx2007
在 adesk.h 中,有变化
#include "AdAChar.h" // ACHAR typedef
而在adaAChar.h 中
typedef wchar_t ACHAR;
//-------------------------------------------
(当初 学习时 经常困扰我的问题,拜读Charles Petzold 先生的大作,幡然醒悟)
[本帖最后由 gangzaishao 于 2007-10-23 10:08 PM 编辑 ]
TOP
本文转自
http://www.objectarx.net/bbs/redirect.php?tid=1244&goto=lastpost