[Scummvm-devel] "free(0)" is valid C, and so is "delete 0;"
Max Horn
max at quendi.de
Sun Aug 1 02:53:04 CEST 2004
Am 01.08.2004 um 09:32 schrieb Eugene Sandulenko:
> Update of /cvsroot/scummvm/scummvm/saga
> In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4757
>
> Modified Files:
> animation.cpp
> Log Message:
> More correct Anim destructor
>
FYI, this change is not doing anything "more correct", it produces
identical code. The C standard specifically defines that free(0) does
nothing. So there is no reason to checking a value for being non-NULL
before freeing it.
To quote the POSIX docs:
"If ptr is a null pointer, no action shall occur."
(Source:
<http://www.opengroup.org/onlinepubs/009695399/functions/free.html>)
Or to quote Microsoft:
"If memblock is NULL, the pointer is ignored and free immediately
returns."
(Source:
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/
vccore98/html/_crt_free.asp>)
The same holds true for "delete 0;", as per the C++ specs.
Not that checking for NULL / 0 will hurt -- I just wanted to make sure
everybody here knows it's just not needed, so that nobody starts
converting our whole sourcebase to have checks :-)
Cheers,
Max
More information about the Scummvm-devel
mailing list