(LPVOID) NULL: unnecessary cast?
I have noticed a lot of constructs of the form: HRESULT WINAPI DMUSIC_CreateDirectMusicScriptImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) { IDirectMusicScriptImpl* obj; obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicScriptImpl)); if (NULL == obj) { *ppobj = (LPVOID) NULL; return E_OUTOFMEMORY; } What's the point of casting NULL to (LPVOID)? Isn't it already a void* anyway? Is it to fix a warning issued by ultra-recent gcc versions? (gcc 3.4.2 does not complain here) Similarly there are a lot of casts like this: *ppobj = (LPVOID)&This->UnknownVtbl; Again I thought any kind of pointer could be assigned to a void* pointer so is this cast really necessary? -- Francois Gouget fgouget(a)free.fr http://fgouget.free.fr/ It really galls me that most of the computer power in the world is wasted on screen savers. Chris Caldwell from the GIMPS project http://www.mersenne.org/prime.htm
On Mon, Dec 13, 2004 at 02:08:31PM +0100, Francois Gouget wrote:
I have noticed a lot of constructs of the form:
HRESULT WINAPI DMUSIC_CreateDirectMusicScriptImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) { IDirectMusicScriptImpl* obj;
obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicScriptImpl)); if (NULL == obj) { *ppobj = (LPVOID) NULL; return E_OUTOFMEMORY; }
What's the point of casting NULL to (LPVOID)? Isn't it already a void* anyway? Is it to fix a warning issued by ultra-recent gcc versions? (gcc 3.4.2 does not complain here)
No, this should work as is. NULL should be able to be assigned to any pointer.
Similarly there are a lot of casts like this:
*ppobj = (LPVOID)&This->UnknownVtbl;
Again I thought any kind of pointer could be assigned to a void* pointer so is this cast really necessary?
This is different and needs to be there. Ciao, Marcus
participants (2)
-
Francois Gouget -
Marcus Meissner