大写VOID宏& INT typedef in winnt.h [英] Purpose of uppercase VOID macro & INT typedef in winnt.h
问题描述
任何人都知道为什么在 winnt.h
头中定义了一个大写的 VOID
/ p>
更令人困惑的是, VOID
是一个宏,而 CHAR
, SHORT
, INT
和 LONG
typedefs。
查看 winnt.h
:
#ifndef VOID
#define VOID void
typedef char CHAR;
typedef short SHORT;
typedef long LONG;
#if!defined(MIDL_PASS)
typedef int INT;
#endif
#endif
历史原因, $ c> VOID *指针而不是 void * pointer
?
EDIT :更糟糕的是,在执行Windows编程时,使用 VOID
而不是 void
今天。您也可以将其视为MSDN文档的一部分,例如 http://msdn.microsoft.com/en-我们/ library / bb205867(v = vs.85).aspx
原来的原因是Win32 API最初应该是独立于语言的,所以他们组成自己的名字(遵循它们的命名约定),然后提供了一个C的实现。在现实中,他们定义的大部分内容往往被大多数使用其他语言的人忽略(并且很大程度上甚至由使用C的人使用)。
为什么 VOID
是 #define
而不是 typedef
这很简单:所需的 typedef
将为 typedef void VOID;
编辑:作为定义从微软的C编译器从那时起)根本不允许,所以他们使用一个宏。
Anyone any clue as to why there is an uppercase VOID
macro defined in the winnt.h
header?
To make matters more confusing, VOID
is a macro, whereas CHAR
, SHORT
, INT
, and LONG
are typedefs.
See the relevant excerpt from winnt.h
:
#ifndef VOID
#define VOID void
typedef char CHAR;
typedef short SHORT;
typedef long LONG;
#if !defined(MIDL_PASS)
typedef int INT;
#endif
#endif
A historical reason perhaps for doing VOID* pointer
instead of void* pointer
?
EDIT: What is even more troubling is to see people using VOID
instead of void
when doing Windows programming today. You can also see it as part of MSDN docs, e.g. http://msdn.microsoft.com/en-us/library/bb205867(v=vs.85).aspx
The original reason is that the Win32 API was originally supposed to be language independent, so they made up their own names (following their naming convention), and then provided a C implementation of that. In reality, much of what they defined tends to be ignored by most people using other languages (and largely even by people using C, for that matter).
As far as why VOID
is a #define
instead of a typedef
, that's pretty simple: the required typedef
would be typedef void VOID;
, but C (edit: as "defined" by Microsoft's C compilers from that time) simply doesn't allow that, so they use a macro instead.
这篇关于大写VOID宏& INT typedef in winnt.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!