CodeDoctorJL
CodeDoctorJL

Reputation: 1264

Is there a difference in VOID and void, in c++?

I've read some other questions similar to this, but I still don't know if there is a difference in terms of usage between "VOID" and "void".

I feel uncomfortable using VOID without knowing the exact difference with void.

Any comforting advice is greatly appreciated.

Upvotes: 1

Views: 195

Answers (2)

Iowa15
Iowa15

Reputation: 3079

void is a keyword reserved by the language, but VOID is not. It is defined in "winnt.h" as follows:

#ifndef VOID
#define VOID void

So they are essentially the same and can be used interchangeably. Sometimes one is used in place of the other for conventions' sake, but it doesn't matter which one you use. The preprocessor will end up replacing VOID with void in your code anyway because that is what #define does.

Actually a lot of keywords are "typedefed" in Windows to their capital. I think it is just to ensure compatibility between 8-bit, 16-bit and 32-bit Windows. Why they did that with void though... That's just Windows being weird. (As far as I know)

Upvotes: 5

Carl Norum
Carl Norum

Reputation: 225032

The difference is that void is part of the language and VOID is not. If you look at the output of the preprocessor for one of your source files containing VOID, you should be able to find a line that contains a line something like:

typedef void VOID;

Which should make you feel better.

Edit: I see from your comment above that there's a #define VOID void line. In that case, you know they're the same, but you likely won't see any VOID in the preprocessor output. What you will see, is that everywhere in your code that you used VOID, the preprocessed output will have void instead.

Upvotes: 3

Related Questions