Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 ggr 10/10/85; site bentley.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!bentley!kwh From: kwh@bentley.UUCP (KW Heuer) Newsgroups: net.lang.c Subject: Re: Address of array; really structure & [array] passing Message-ID: <694@bentley.UUCP> Date: Sun, 6-Apr-86 14:36:04 EST Article-I.D.: bentley.694 Posted: Sun Apr 6 14:36:04 1986 Date-Received: Wed, 9-Apr-86 08:11:04 EST References: <456@cubsvax.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner Lines: 31 In article <456@cubsvax.UUCP> cubsvax!peters (Peter S. Shenkin) writes: >A naive question. When a structure ... is passed [by value], doesn't >everything in it have to be copied at execution time ...? Wouldn't this >also have to occur if arrays could be passed by value? >If the structures/arrays are large, doesn't this incur a large overhead? Yes, though it's partially reduced if the architecture has a fast block- move instruction. >That is, it seems to be a tradeoff between programming ease and syntactical >elegance, on the one hand, versus time as well as space, on the other. >I'm not trying to make a general argument against pass-by-value for structures >[or arrays], but isn't the practice best avoided when large structures may >be expected? Indeed, most call-by-value and return-by-value structures are small (complex numbers, coordinates of a point, etc.). Almost all structures are passed by reference. Presumably if arrays had been implemented "correctly", programs would still pass them by reference ("f(&a)" or "f(&a[0])") except in special cases. >On rereading this, perhaps I'm wrong; if I declare > struct { float array[MANY]; } sarray; >and call > result = func(sarray); >are all the elements of sarray.array passed to func(), or is just the >address of the array copied when the structure is passed? Enlighten me! The entire structure is copied, including all the elements of the array. This is the standard kludge for passing an array or a float by value (e.g. to a routine written in another language).