简体   繁体   English

为什么typedef char CHAR

[英]Why typedef char CHAR

Guys, having quick look in Winnt.h I have discovered that there is a lots of typedefs and one of them is for example CHAR for a char. 伙计们,快速浏览一下Winnt.h我发现有很多typedef,其中一个是例如char的char。 Why? 为什么? What was the purpose of these typdefs? 这些typdefs的目的是什么? Why not use what's already there (char, int etc.)? 为什么不使用已经存在的东西(char,int等)?
Thank you. 谢谢。

The win32 API needs to be language agnostic. win32 API需要与语言无关。 The typedefs are tied to actual item sizes on the x86 processor. typedef与x86处理器上的实际项目大小相关联。 Thus CHAR is char, DWORD is unsigned long.... It's all so that languages other than C and C++ can "plug in" to the API even with differing memory models. 因此CHAR是char,DWORD是无符号长的......除了C和C ++以外的语言,即使使用不同的内存模型,也可以“插入”API。

The WIN32 API needs to be platform agnostic as well. WIN32 API也需要与平台无关。 When the compiler adjusts for different word sizes, the types may also change as well. 当编译器针对不同的字大小进行调整时,类型也可能会发生变化。

For example, on 16-Bit platforms: 例如,在16位平台上:

typedef WORD unsigned int;
typedef DWORD unsigned long;

On 32-bit platforms: 在32位平台上:

typedef WORD unsigned short;
typedef DWORD unsigned int;

This an example, your mileage may vary. 这个例子,您的里程可能会有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM