🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #5805

Re: realloc

#5805
From: Kenneth Almquist
Date: Sat, 01 Apr 1989 08:11
30 lines
1673 bytes
hascall@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@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
Technical Details
Message-ID: <7744@june.cs.washington.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!husc6!rice!uw-beaver!uw-june!ka
References: <10170@bloom-beacon.MIT.EDU> <10032@ihlpb.ATT.COM> <934@atanasoff.cs.iastate.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!husc6!rice!uw-beaver!uw-june!ka
From: ka@june.cs.washington.edu (Kenneth Almquist)
Newsgroups: comp.std.c,comp.lang.c
Subject: Re: realloc
Message-ID: <7744@june.cs.washington.edu>
Date: 1 Apr 89 08:11:34 GMT
References: <10170@bloom-beacon.MIT.EDU> <10032@ihlpb.ATT.COM> <934@atanasoff.cs.iastate.edu>
Organization: U of Washington, Computer Science, Seattle
Lines: 30