(LPVOID) NULL: unnecessary cast?

Francois Gouget fgouget at free.fr
Mon Dec 13 07:08:31 CST 2004


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 at 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



More information about the wine-devel mailing list