简体   繁体   中英

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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