effect of free()

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Sep 9 16:00:32 AEST 1989


In article <9278 at attctc.Dallas.TX.US> chasm at attctc.Dallas.TX.US (Charles Marslett) writes:
>Because one special invalid pointer has to be acceptable in all expressions
>except dereferencing (NULL, that is), ...

No!  Null pointers do NOT have to be represented by invalid addresses.
They merely have to be distinct from any address of valid objects that
a strictly conforming C program could access.  There are no performance
penalties required to implement null pointers even in an architecture
that traps on loading invalid addresses.

>Why don't we just say is it lousy looking code that does this sort of thing --
>so don't do it (even though it will work 99999 times out of 10000, or whatever
>the fraction really is.

Good advice; since it is not necessary to rely on the nonportable
ability to continue to play with a pointer after it is free()d,
it is best to simply avoid doing so.



More information about the Comp.lang.c mailing list