[Scummvm-devel] "free(0)" is valid C, and so is "delete 0;"
Max Horn
max at quendi.de
Sun Aug 1 16:23:01 CEST 2004
Am 02.08.2004 um 01:05 schrieb John Willis:
>> If I learned one thing, it's "Never say never". But I can say that
>> none
>> of our target platforms has such a hideous buggy standard library --
>> else our existing code wouldn't work (as it already relies on this).
>
> *cough*, GP32 port, *cough* ;-)
>
> That said it's largely academic as the CVS code is long past working
> anyway
> (I REALLY must submit a patch as soon as my code works again).
Indeed.
> GCC when implemented on the GP32 (using its SDK Malloc/Free wrappers)
> actually needs VERY evil hacks that effectively map New and Delete to
> wrapped Malloc and Free (and none of those wrappers are completely
> predicable when chucked things like (0)).
Just to clarify one thing: Neither new/delete nor malloc/free are
something implemented by the compiler. Rather, they are library
functions. So any deficiencies are in the libraries, not the compiler!
> e.g.
>
> void* operator new[]( size_t size ) throw(std::bad_alloc) {
> return ::gm_malloc(size);
> }
I don't see your point -- if you provide a custom operator new or
delete, you can easily make it standard compliant by allowing 0
values...
> My current code wraps the SDK Malloc and Free to fix the
> implementation but
> unfortunately I broke the port against CVS recently and I have not
> worked
> out what is wrong yet ;-) (I think I broke the String class, no idea
> how).
>
> For what it's worth I would make the point this it might make sense to
> standardise on a Malloc/Free or New/Delete strategy (recent commits
> seem to
> hint at some mixing) and 'maybe' mention the (0) assumption in the code
> docs.
I am not sure what you mean with "a Malloc/Free or New/Delete
strategy". Would you please elaborate?
As for the "(0) assumption": as was stated previously on this thread,
it's not an assumption, it's what the C/C++/POSIX/MicroSoft/other specs
*require* of any compliant C standard library. We don't document how we
expect the "fopen" function to work either...
Bye,
Max
More information about the Scummvm-devel
mailing list