开发者

Why typedef char CHAR

开发者 https://www.devze.com 2022-12-28 17:00 出处:网络
Guys, having quick look in开发者_如何学C Winnt.h I have discovered that there is a lots of typedefs and one of them is for example CHAR for a char. Why? What was the purpose of these typdefs? Why not

Guys, having quick look in开发者_如何学C Winnt.h I have discovered that there is a lots of typedefs and one of them is for example CHAR for a char. Why? What was the purpose of these typdefs? Why not use what's already there (char, int etc.)?

Thank you.


The win32 API needs to be language agnostic. The typedefs are tied to actual item sizes on the x86 processor. 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.


The WIN32 API needs to be platform agnostic as well. When the compiler adjusts for different word sizes, the types may also change as well.

For example, on 16-Bit platforms:

typedef WORD unsigned int;
typedef DWORD unsigned long;

On 32-bit platforms:

typedef WORD unsigned short;
typedef DWORD unsigned int;

This an example, your mileage may vary.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号