Re: Question about 'C' code and use of "void"
- From: "John Carson" <jcarson_n_o_sp_am_@xxxxxxxxxxxxxxx>
- Date: Sun, 4 Jun 2006 16:55:47 +1000
"Stick" <Stick@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:52F0E3D7-E25F-4865-9E1E-3DDF3CC7151E@xxxxxxxxxxxxx
In code I'm reviewing I see this:
typedef void *PVOID; // <-- This line troubles me.
typedef PVOID *PPVOID;
And I'm confused becasue void is, of course, a keyword. Looks like
someone is trying to redefine the meaning of void, but I'm at a lose
as to why.
Stick
You are confusing #define syntax with typedef syntax. In simple cases,
typedef syntax is the "other way around" so that the last identifier is the
thing being defined.
More generally, typedef syntax is deliberately meant to mirror variable
declaration syntax. To define a new typename, you write the code for
declaring an instance of that type, then put typedef in front of the
declaration. Your variable name then becomes a typename.
Thus
int INT;
declares a variable called INT of type int, while
typedef int INT;
declares a typename called INT that is an alias for int.
Similarly
void * PVOID;
declares a variable called PVOID of type void *, while
typedef void * PVOID;
declares a typename called PVOID that is an alias for void *.
It works for function pointers to. Thus
void (*fnptr)(int);
declares a variable called fnptr that is a pointer to a function that takes
an int argument and returns void, whereas
typedef void (*fnptr)(int);
declares a typename called fnptr that is an alias for the type of a pointer
to a function that takes an int argument and returns void.
--
John Carson
.
- Follow-Ups:
- Re: Question about 'C' code and use of "void"
- From: Alexander Grigoriev
- Re: Question about 'C' code and use of "void"
- Prev by Date: Re: Question about 'C' code and use of "void"
- Next by Date: Stack Tracing
- Previous by thread: Re: Question about 'C' code and use of "void"
- Next by thread: Re: Question about 'C' code and use of "void"
- Index(es):
Relevant Pages
|