What does malloc(0) return?

Phil Howard KA9WGN phil at ux1.cso.uiuc.edu
Sat Jun 1 06:49:54 AEST 1991


steve at unidata.ucar.edu (Steve Emmerson) writes:

>Greetings,
>
>The subject-line says it all and my K&R2 is silent on the matter.
>Is the answer NULL, non-NULL (but don't dereference), undefined,
>or implementation-defined?

If it did return the address of somewhere in memory, you cannot
dereference that pointer without exceeding the size.

It would be more useful if it did return something consistent like NULL.
Prior to this posting, had I needed to implement malloc(0) I am sure
I would have just implemented it to return NULL in that case unless
I found a reason not to.
-- 
 /***************************************************************************\
/ Phil Howard -- KA9WGN -- phil at ux1.cso.uiuc.edu   |  Guns don't aim guns at  \
\ Lietuva laisva -- Brivu Latviju -- Eesti vabaks  |  people; CRIMINALS do!!  /
 \***************************************************************************/



More information about the Comp.std.c mailing list