effect of free()

Richard H. Gumpertz rhg at cpsolv.UUCP
Sat Sep 9 01:23:20 AEST 1989


Re: loading the value of the pointer into a register to test it may cause a
fault ...

Seems to me that a compiler should avoid loading the pointer into a register
if that might cause a fault!  The pointer comparison context is fundamentally
different from the pointer indirection context; the former should be able to
work with invalid pointer values (at least when the comparison is to NULL)
while the latter may fault.

Surely the compiler implementor can find a code sequence that avoids faults
when comparing invalid pointers to NULL!  (For example, load the pointer into
an appropriately sized data register instead of an address register.)

By the way, the standard (3.3.9) lists all sorts of constraints on pointer
comparison of the form "operand is a pointer to an object" but then leaves off
"to an object" in the clause mentioning comparisons to NULL.  That may be
significant (although they may have only been allowing the pointer to be NULL
as opposed to invalid).



More information about the Comp.lang.c mailing list