realloc

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Mar 30 01:48:43 AEST 1989


In article <10170 at bloom-beacon.MIT.EDU> scs at adam.pika.mit.edu (Steve Summit) writes:
>Today, for the third time in half as many years, I got badly
>burned, and wasted lots of time, due to a bug in a certain
>vendor's implementation of realloc.  It is an apparently well-
>kept secret that realloc is supposed to behave gracefully at
>a slightly special-cased boundary point: when handed a NULL
>pointer and a nonzero size, it acts essentially as a malloc.

While that's required for ANSI C standard conformance, in fact
many existing C implementations do not behave that way, and it
isn't advertised behavior even in the current UNIX release (I
don't think it even works that way).  Therefore it is unwise to
rely on this behavior in an application intended for a
not-necessarily-ANSI-conforming environment.

So why standardize this uncommon behavior?  I think the intent
was to make programming easier at some future date when nearly
all C environments will be standard conforming.



More information about the Comp.std.c mailing list