Article View: comp.std.c
Article #4475Re: Should free() take a pointer to const argument?
From: Stan Ryckman
Date: Thu, 14 Dec 1995 18:32
Date: Thu, 14 Dec 1995 18:32
34 lines
2013 bytes
2013 bytes
In article <4apkl2$8sp@rdsunx.crd.ge.com>,
Christopher R. Volpe <volpe@ausable.crd.ge.com> wrote:
|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
^^^^^^^^^^^^^
Well, you might 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.
Consider the Intel segmented addressing. Many 32-bit pointers can
point to the same 20-bit address. They will not match when compared
as bytes. realloc() could return any of those.
Cheers,
Stan.
--
HELP! I'M BEING HELD PRISONER IN A .SIGNATURE FACTORY!
Stan Ryckman sgr@alden.com
Technical Details
Message-ID:
<4apqk8$8c6@ae-sun01.alden.com>Path:
arc1-ca.pugleaf.net!alden.com!not-for-mailReferences:
<818626119snz@genesis.demon.co.uk> <4am3dn$6s9@natasha.rmii.com> <818898225snz@genesis.demon.co.uk> <4apkl2$8sp@rdsunx.crd.ge.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!alden.com!not-for-mail From: sgr@ae-sun01.alden.com (Stan Ryckman) Newsgroups: comp.std.c Subject: Re: Should free() take a pointer to const argument? Date: 14 Dec 1995 13:32:40 -0500 Organization: Amber & Sneakers Fan Club Message-ID: <4apqk8$8c6@ae-sun01.alden.com> References: <818626119snz@genesis.demon.co.uk> <4am3dn$6s9@natasha.rmii.com> <818898225snz@genesis.demon.co.uk> <4apkl2$8sp@rdsunx.crd.ge.com> NNTP-Posting-Host: ae-sun01.alden.com