effect of free()

Barry Margolin barmar at think.COM
Thu Sep 21 04:50:43 AEST 1989


In article <125 at bbxsda.UUCP> scott at bbxsda.UUCP (Scott Amspoker) writes:
>In article <591 at augean.OZ>  writes:
>>C used to be a language where I felt comfortable because I had a pretty
>>good idea of its basic principles...
>there is a fear that our old friend, C, has become a 
>Marxist dictator (for our own good of course).

As has been said umpteen times in this thread, C hasn't changed (at
least not in this respect).  It has always been true that the results
of handling an invalid pointer were implementation-dependent.  The
only thing that has changed as a result of the pANS is the fact that
this portability problem is now documented; it used to be an unstated
fact.

To users, the pANS isn't a dictator, it's a mentor.  It's a
portability guide.  It doesn't say "you'll go to jail if you access
pointer variables that point to freed storage".  It says that programs
that do so could encounter portability problems.  This was true before
X3J11 was formed, and they've merely acknowledged it.  Prior to
X3J11's work such programs weren't maximally portable, but you didn't
know it; the only difference is that now you know it.

About the only bad effect this point in the standard could have is
that it may give unfortunate ideas to some implementors, who might
then go out of their way to make free() do weird things.  The
lattitude exists in the standard to allow C to map into the most
natural mechanism for a system, not to encourage intentionally
confusing behavior.  Referencing invalid pointers is allowed to trap
for the same reason that positive/negative is allowed to round either
up or down (personally, I think the implementation-dependent behavior
of "/" and "%" is one of C's biggest warts, but I know that it's way
too late to change it).

Barry Margolin
Thinking Machines Corp.

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



More information about the Comp.lang.c mailing list