Re: Using malloc in C++?
On Jun 7, 1:37 pm, Gianni Mariani <gi3nos...@mariani.ws> wrote:
Ian Collins wrote:
Gianni Mariani wrote:
Ian Collins wrote:
....
malloc(0)
Specified as far as you will either get a pointer to a block of >0 by=
tes
or NULL, just like any other size.
That would be a problem then.
Why? What ever you get from malloc, you can pass to free.
Different behaviour on different systems. If I write code that assumes
malloc(0) returns unique values and it returns 0 on some, it will break.
I'm not sure if that's the only one but it is a source of inconsistency
between platforms.
And how is this different from new? If you allocate an array of
length 0 with new, it may fail, or it may return a unique
pointer, which can be copied and tested, but not deallocated.
Just like malloc.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34