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 Windows API is old. Really old. Older than the official C standard old.
This means that, at the start, the Windows API had to deal with all kinds of ancient C compilers, with different levels of language support. Some might not support void
. Some might have an int
type that's not compatible with what windows thought was int
. Some might not understand short
. As a workaround, the Windows API provides upper-case portable equivalents that are aliased to whatever works for that particular compiler.
Of course, with modern compilers, things have settled down quite a bit. Everyone supports void
, for example. However, in order to maintain compatibility with old code that uses these upper-case macros, the #define
s and typedef
s have to remain.
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 (as "defined" by Microsoft's C compilers from that time) simply doesn't allow that, so they use a macro instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With