(LPVOID) NULL: unnecessary cast?

Marcus Meissner meissner at suse.de
Mon Dec 13 07:42:14 CST 2004


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-devel/attachments/20041213/ba06abda/attachment.pgp


More information about the wine-devel mailing list