[Scummvm-devel] "free(0)" is valid C, and so is "delete 0;"

John Willis John.Willis at Distant-Earth.Co.Uk
Sun Aug 1 16:48:00 CEST 2004


All,

I blame it being 1am for me writing such non-intelligible drivel ;-).

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

Ok, I could have worded that better by saying 'by default the GP32 official
SDK library memory code (as used by the ScummVM port) is not 100% standards
compliant' and left it at that :-). GCC did not really need to be mentioned
in that paragraph at all ;-).

That would have highlighted the point with making me look like a prize prat.

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

Ok, to elaborate. ScummVM has historically use Malloc and Free for memory
handling despite being C++ in nature. Recently I 'thought' I noticed a trend
for check-ins to start to use New and Delete for memory handling leading to
2 separate approaches to memory handling. 

However upon rechecking my logs I was just being particularly dense and this
is NOT the case (I really should not scan read CVS logs). 

Comment willingly withdrawn ;-).

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

Fine ;-). Sounds fair.

Regards,

	John







More information about the Scummvm-devel mailing list