Addresses of parameters (was Re: Portability of passing/operating ...)

Richard Harter g-rh at XAIT.Xerox.COM
Wed Oct 26 17:03:11 AEST 1988


In article <41337 at yale-celray.yale.UUCP> wald-david at CS.YALE.EDU (david wald) writes:
>In article <35569 at XAIT.Xerox.COM> g-rh at XAIT.Xerox.COM (Richard Harter) writes:

>>       This is a good example.  It contains two coding techniques that I
>>do not use and, indeed, would not think of using.  The first is taking
>>the address of a function parameter.  The second is initialization to a
>>dynamic quantity....

>I'm not sure why you consider the first of these a dubious construct.
>(The second I am willing to consider a non-portable abbreviation for an
>extra line of code.) I can't think of an architecture where this would
>be unusually difficult to implement, and on most architectures it would
>be as easy as taking the address of any automatic variable.  Is it
>dubious only because there are compilers which break on it, or is there
>a more basic reason?

	There are two reasons.  One is technical, the other is a matter
of general principles.  The technical reason is that a calling sequence
parameter need not have an address.  Consider a hypothetical machine P
which passes the first n arguments through registers.  Taking the address
of such an argument would then be equivalent to taking the address of a
register.  I will grant that it is easy enough to put a kludge in the 
compiler to get around this; any parameter whose address is referred to
is copied onto the stack and that becomes the effective location.  But it
is a kludge and there is no guarantee that the compiler writers will handle
this for you (particularly in a a one pass compiler!)

	The reason that this is bad as a matter of general principles is
that the address of a calling sequence parameter is not a meaningful
thing.  Arguments in C are copies of the parameters passed.  The address
(if it exists) is the address of the copy; it is not, so to speak, an
address of a real object.  The general point is that calling sequence
parameters are a different breed of cat from other variables.  Taking the
address of a calling sequence parameter implicitly ignores one of the
respects in which they are different.

-- 

In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die.
	Richard Harter, SMDS  Inc.



More information about the Comp.lang.c mailing list