realloc

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Apr 1 08:16:39 AEST 1989


In article <9122 at alice.UUCP> andrew at alice.UUCP (Andrew Hume) writes:
>gregg townsend reminds us of the pANS ``feature'' that malloc(0) returns NULL.
>can anyone provide the (or any) justification of this pointless stupid
>definition?

Sure.  malloc() either fails or it succeeds.  If it were required to
succeed for a 0-sized allocation attempt, then additional semantics
would have had to have been devised to deal with the 0-sized object
pointed to by the returned non-null pointer.  For example, should
a series of malloc(0) calls return distinct pointers?  Anyway, for
the limited additional functionality this was considered too big a
can of worms to open.

Happens I'm the POC for 0-sized object extensions to C.  There has
so far been a distinct lack of interest in this area..



More information about the Comp.lang.c mailing list