This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: malloc attributes and realloc


Bruce Korb <bkorb@veritas.com> writes:

> "Joseph S. Myers" wrote:
>> 
>> On Thu, 1 Jan 2004, Bruce Korb wrote:
>> 
>> > Even if what was addressed by 'p' is no longer valid, it is certainly
>> > still valid to test to see if 'q' differs from 'p'.
>> 
>> No; 6.2.4#2 says that "The value of a pointer becomes indeterminate when
>> the object it points to reaches the end of its lifetime.";
>
> That's nice.  Were there a compiler that were to take that clause
> and use it to destroy the semantics of a program, I would expect
> and actually hope that compiler would disappear and never see the
> light of day again.  I am reaching the conclusion that too much of
> the standard was written by lawyers out of touch with real programming.

This is by no means theoretical only.  Think of a segmented
architecture, where loading an invalid value into a segment register
generates a trap.  On such an architecture freeing an object can mean
making the segment invalid.  If you try to use a pointer to such an
object later it would load the invalid segment value and a trap
occurs.  Note that you don't need to dereference the pointer to get
the trap.  Such architectures did actually exist, and it is
unreasonable to require to check for a valid segment for every use of
a pointer.

Try searching for "invalid segment" in comp.std.c.  There are some old
threads about this topic.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, MaxfeldstraÃe 5, 90409 NÃrnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]