When writing code and reading code, you often see this code: typedef void *handle, where is it sacred? How to understand it?
Do not understand it, feel it is very magical, know it later, it is a typedef definition, but is the void* type, that is, handle equivalent to void *, we can call it in the handle of the skin of the pointer (PS: pointer and handle is a difference, in this say nonsense);
For void*, because it is a function parameter or function return value, can accept any kind of pointer; that is, the pointer is accepted (so open, Aha). However, when applied, it should be noted that void * must point to a specific type;
void * HAPPYPT;
int* pi=static_cast<int*>happypt;; Attention, here specifically to the int* Oh!
The specific usage is as follows:
1. Do you remember it?
void * __cdecl memset (_out_opt_bytecapcount_ (_size) void * _DST, _in_ int _val, _in_ size_t _size);
This is the prototype of this function, where you can memset void* to Handle,memset is to transfer the address of the beginning of the N-byte value of all assigned to a specific value, so there is no need to know what type of pointer, with the void type pointer instead. When used as a parameter, we generally do not care about the type of address passed in;
When used as a return value, usually returns an address, as to what you want to do with this address you decide, the most common is malloc, which returns the void type pointer as the first address of the allocated memory area, as to what type, it needs the user to specify.
Example
typedef void *handle;
HANDLE m_exitthreadevent;
M_exitthreadevent = CreateEvent (null,false,false,null);
HANDLE CreateEvent (
Lpsecurity_attributes Lpeventattributes,
BOOL bManualReset,
BOOL Binitialstate,
LPTSTR lpname
);
typedef of C + + void *handle