Article View: comp.std.c
Article #4471Re: Should free() take a pointer to const argument?
From: Christopher R. Volpe
Date: Thu, 14 Dec 1995 16:50
Date: Thu, 14 Dec 1995 16:50
22 lines
1707 bytes
1707 bytes
In article <818898225snz@genesis.demon.co.uk>, Lawrence Kirby <fred@genesis.demon.co.uk> writes:
|>
|>realloc can be thought of as destroying an object (without modifying it)
|>and then creating another one initialised to (an appropriate amount of)
|>the data that was in the first one. This makes sense because no pointer to
|>the original object is valid so long as the call to realloc succeeds. I
|>don't see a problem with shrinking the allocation when the initial and final
|>objects are viewed as distinct. Even if the realloc call returns the same
|>address as the one passed to it no strictly conforming program can rely on
|>this fact or even detect it since all pointers to the original object are
^^^^^^^^^^^^^^
You can detect it. Before calling realloc, look at the pointer value as an
array of (sizeof(void *)) bytes, and save those bytes somewhere. Then compare
bytes after the realloc. You're not evaluating the pointer, just inspecting
byte values.
--
Chris Volpe Phone: (518) 387-7766 (Dial Comm 8*833
GE Corporate R&D Fax: (518) 387-6560
PO Box 8, Schenectady, NY 12301 Email: volpecr@crd.ge.com
Technical Details
Message-ID:
<4apkl2$8sp@rdsunx.crd.ge.com>Path:
arc1-ca.pugleaf.net!bart.crd.ge.com!volpeReferences:
<818626119snz@genesis.demon.co.uk> <4am3dn$6s9@natasha.rmii.com> <818898225snz@genesis.demon.co.uk>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!bart.crd.ge.com!volpe From: volpe@bart.crd.ge.com (Christopher R. Volpe) Newsgroups: comp.std.c Subject: Re: Should free() take a pointer to const argument? Date: 14 Dec 1995 16:50:42 GMT Organization: GE Corporate Research & Development Sender: volpe@bart (Christopher R. Volpe) Distribution: world Message-ID: <4apkl2$8sp@rdsunx.crd.ge.com> References: <818626119snz@genesis.demon.co.uk> <4am3dn$6s9@natasha.rmii.com> <818898225snz@genesis.demon.co.uk> Reply-To: volpe@ausable.crd.ge.com NNTP-Posting-Host: bart.crd.ge.com