realloc

Kenneth Almquist ka at june.cs.washington.edu
Sat Apr 1 18:11:34 AEST 1989


hascall at atanasoff.cs.iastate.edu (John Hascall) writes:
>     And what would you have malloc(0) return?   An Address?
What else?

>    ...which points to zero bytes of allocated storage?
At least zero bytes.

>    And would successive malloc(0) calls return the same pointer?
No.

>    (you're not using any heap with each call)
Yes you are, because malloc has to record the size of the allocated
block somewhere.

>    And then consider doing a "free" on such a pointer.
Makes as much sense as freeing any other pointer.

That's what existing UNIX malloc implementations do, and as I understand
it there is nothing in the ANSI C standard that prohibits this behavior.


In article <3810 at geaclib.UUCP>, David suggests writing a program that
tests whether the realloc implementation is ANSI compliant, and using
it to conditionally compile a wrapper routine around realloc.  There is
no guarantee that the test program will work ("Testing can never show
the absense of bugs, only their presense."), although it should be
possible to write a wrapper routine that will work well enough in
practice.  Personally, I wouldn't bother; it seems simpler to just use
the wrapper routine all the time.
				Kenneth Almquist



More information about the Comp.lang.c mailing list