effect of free()

Barry Margolin barmar at think.COM
Tue Sep 19 07:33:28 AEST 1989


In article <1693 at levels.sait.edu.au> CCDN at levels.sait.edu.au (DAVID NEWALL) writes:
>In article <11070 at smoke.BRL.MIL>, gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
>> In particular, there is a school of thought that says machine architecture
>> should be designed to assist in program reliability.  That school
>> occasionally influences computer architectures such that actions like
>> merely continuing to shuffle around invalid pointers cause an error trap
>> to be taken.
>That is supposed to make programs reliable?

Yes.  The idea is that a program that tries to manipulate invalid
pointers is doing so inadvertently.  The hope is that the trap will be
invoked while the program is being tested, and the bug will be fixed.
And even if the trap isn't triggered during testing, it might be
triggered by an end user, who should report that the program crashed
under such-and-such a circumstance, which will permit the developers
to fix the bug.  An architecture that doesn't trap is allowing the
program to perform a presumably-unintended operation.

>Testing parameters for "correctness", rather than blindly hoping that they
>are "correct", is one way to make programs more reliable.

Unfortunately, there is no C operation that tests parameters for
"correctness".  Supposing C allowed invalid pointers to be referenced,
what would you use to test parameters for correctness?  The program
fragment "if (ptr != NULL)" has been bandied about quite a bit in this
chain, but it isn't useful for determining whether a pointer is valid
or not; it would do the same thing for an invalid pointer and a valid,
non-null pointer.

Barry Margolin
Thinking Machines Corp.

barmar at think.com
{uunet,harvard}!think!barmar



More information about the Comp.lang.c mailing list