[comp.std.c] Could a function change its argument

tarvaine@tukki.jyu.fi (Tapani Tarvainen) (08/24/89)

Assume an architecture where 
(1) address registers are special so that putting or even having
    an invalid pointer there will cause a trap; and
(2) there are enough of them to spare.

Question:  Could they be used for register variables?
How could free() be implemented?

More specifically, would it be legal to implement free() so
that it checks all such registers and trashes them (substituting
some harmless value) if they contain a pointer which becomes
invalid (points into the freed area)?

After all, it's illegal to do anything which them afterwards
anyway.

A case where a function could change not only its arguments
but also other variables never mentioned in the call!?
-- 
Tapani Tarvainen    (tarvaine@tukki.jyu.fi, tarvainen@finjyu.bitnet)

rns@se-sd.NCR.COM (Rick Schubert ) (08/26/89)

In article <1190@tukki.jyu.fi> tarvaine@tukki.jyu.fi (Tapani Tarvainen) writes:
>More specifically, would it be legal to implement free() so
>that it checks all such registers and trashes them (substituting
>some harmless value) if they contain a pointer which becomes
>invalid (points into the freed area)?

There is a principle that states that the implementation may do anything if
a conforming program cannot tell the difference (I think this is part of
the "as if" rule).  This would seem to apply here.  Since there doesn't
appear to be any way that a conforming program could use the contents of
such registers (until they are reassigned legitimate values), it doesn't
seem like it would make any difference if they were trashed.

-- Rick Schubert (rns@se-sd.sandiego.NCR.COM)