Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!ukma!nrl-cmf!ames!husc6!xait!g-rh From: g-rh@XAIT.Xerox.COM (Richard Harter) Newsgroups: comp.lang.c Subject: Re: Addresses of parameters (was Re: Portability of passing/operating ...) Message-ID: <35620@XAIT.Xerox.COM> Date: 26 Oct 88 07:03:11 GMT References: <8810111934.AA21941@ucbarpa.Berkeley.EDU> <8308@alice.UUCP> <23933@wlbr.EATON.COM> <1988Oct19.192548.28438@ateng.ateng.com> <35 <35569@XAIT.Xerox.COM> <41337@yale-celray.yale.UUCP> Reply-To: g-rh@XAIT.Xerox.COM (Richard Harter) Organization: Xerox Corporation, Cambridge, Massachusetts Lines: 41 In article <41337@yale-celray.yale.UUCP> wald-david@CS.YALE.EDU (david wald) writes: >In article <35569@XAIT.Xerox.COM> g-rh@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.