From: (see below) on 25 Feb 2010 14:52 On 24/02/2010 20:37, in article hm6fbd68gp(a)news6.newsguy.com, "Michael Wojcik" <mwojcik(a)newsguy.com> wrote: > (see below) wrote: >> >> Just the usual red tape: return address, frame pointer of caller; and either >> a static pointer or some housekeeping for 'display' registers (if used) to >> access non-locals. But bear in mind that in decent languages arrays are >> storable values, so a value array parameter gets copied in toto, unlike C. > > It will be in C if the array is wrapped in a struct. Letting array That is passing a struct, not an array. > parameters decay to pointers was a feature of early C that couldn't be > changed for historical reasons, but when the standardization committee > added support for struct parameters, they made them first-class. > struct (and not the misnamed "typedef") is C's mechanism for creating > new types and ADTs, so if you want a pass-by-value array in C, the > correct thing to do is to put it in a struct. Yes. Preposterous, isn't it? > This is not to say that C's parameter passing doesn't still have a > number of infelicities. Exposing the use of pointers to implement > pass-by-reference (which C lacks, strictly speaking) has some > advantages, but it has led to great confusion over matters like the > const and restrict qualifiers. To say the least of it. -- Bill Findlay <surname><forename> chez blueyonder.co.uk
From: (see below) on 25 Feb 2010 14:59 On 25/02/2010 17:34, in article e8b9b29d-a8fe-4b4a-8365-ffccf6321bdd(a)o3g2000yqb.googlegroups.com, "Eric Chomko" <pne.chomko(a)comcast.net> wrote: > On Feb 24, 6:20�pm, "(see below)" <yaldni...(a)blueyonder.co.uk> wrote: >> On 24/02/2010 19:31, in article >> d902c75e-e33a-4281-a796-7c56c3276...(a)o16g2000prh.googlegroups.com, "Eric >> >> >> >> Chomko" <pne.cho...(a)comcast.net> wrote: >>> On Feb 23, 2:07 pm, "(see below)" <yaldni...(a)blueyonder.co.uk> wrote: >>>> On 23/02/2010 17:52, in article >>>> 3ec03225-3a0f-4bcd-9db1-51201d1b3...(a)w12g2000vbj.googlegroups.com, "Eric >> >>>> Chomko" <pne.cho...(a)comcast.net> wrote: >>>>> But an ALGOL "activation record" (stack frame) had a lot more than >>>>> that. As I recall, they copied a lot more just pointers and parameter >>>>> values. >> >>>> Just the usual red tape: return address, frame pointer of caller; and >>>> either >>>> a static pointer or some housekeeping for 'display' registers (if used) to >>>> access non-locals. But bear in mind that in decent languages arrays are >>>> storable values, so a value array parameter gets copied in toto, unlike C. >> >>> Are you saying that C doesn't implement true recursion? I have only >>> used recursion in college and not with C. ALGOL, SIMPL-T and LISP were >>> the only languages I used to write recursive algorithms. >> >> No. I'm at a loss as to how you could put that interpretation on it. > > Perhaps I misunderstood your reference, "unlike C". As I recall the > difference between a global and local variable in a block-structured > language is that a global is statically stored like all FORTRAN IV > variables. And locals get put onto the stack with each call to the > function and are dynamically allocated. It is this last aspect that > allows recursion to occur other than allowing a function to call > itself. True, but I'm still at a loss. How does "so a value array *parameter* gets copied in toto, unlike C" lead you to a consideration of the scope and lifetime of *variables*? >> I'm saying that array parameters in C are not called by value, but they are >> in Algol 60 and cognate languages, requiring more stack space than C does. > > > Doesn't a C stack frame contain a lot less than an ALGOL activation > record other than just parameter information? If you mean the obligatory stuff to implement procedure calls, no, it doesn't; with the possible exception of a static pointer/display (needed in very recent C dialects, but not in versions lacking nested scopes). -- Bill Findlay <surname><forename> chez blueyonder.co.uk
From: Jon Elson on 25 Feb 2010 15:42 Eric Chomko wrote: > > Are you saying that C doesn't implement true recursion? I have only > used recursion in college and not with C. ALGOL, SIMPL-T and LISP were > the only languages I used to write recursive algorithms. > I think he's saying C doesn't, by default, copy entire arrays, it defaults to passing a pointer to the array. If a recursive procedure NEEDS the array to be copied, there are mechanisms to do that. But, of course, copying the pointer only is more efficient both in time and memory. Jon
From: glen herrmannsfeldt on 25 Feb 2010 16:32 In comp.arch.fpga Jon Elson <jmelson(a)wustl.edu> wrote: > Eric Chomko wrote: >> Are you saying that C doesn't implement true recursion? I have only >> used recursion in college and not with C. ALGOL, SIMPL-T and LISP were >> the only languages I used to write recursive algorithms. > I think he's saying C doesn't, by default, copy entire arrays, it > defaults to passing a pointer to the array. If a recursive procedure > NEEDS the array to be copied, there are mechanisms to do that. But, of > course, copying the pointer only is more efficient both in time and memory. But local arrays are automatic in C. I would think that would usually work fine for recursion. K&R required initialized arrays to be static, which doesn't seem like a bad requirement to me. (Fortran requires all initialized variables to be static.) -- glen
From: Scott Lurndal on 25 Feb 2010 18:26
"(see below)" <yaldnif.w(a)blueyonder.co.uk> writes: >On 24/02/2010 20:37, in article hm6fbd68gp(a)news6.newsguy.com, "Michael >Wojcik" <mwojcik(a)newsguy.com> wrote: > >> (see below) wrote: >>> >>> Just the usual red tape: return address, frame pointer of caller; and either >>> a static pointer or some housekeeping for 'display' registers (if used) to >>> access non-locals. But bear in mind that in decent languages arrays are >>> storable values, so a value array parameter gets copied in toto, unlike C. >> >> It will be in C if the array is wrapped in a struct. Letting array > >That is passing a struct, not an array. > >> parameters decay to pointers was a feature of early C that couldn't be >> changed for historical reasons, but when the standardization committee >> added support for struct parameters, they made them first-class. > >> struct (and not the misnamed "typedef") is C's mechanism for creating >> new types and ADTs, so if you want a pass-by-value array in C, the >> correct thing to do is to put it in a struct. > >Yes. Preposterous, isn't it? Q? Why would anyone want to pass an array by value? scott |