From: Charles Richmond on
glen herrmannsfeldt wrote:
> In comp.arch.fpga Scott Lurndal <scott(a)slp53.sl.home> wrote:
> (snip, someone wrote)
>>>> Q? Why would anyone want to pass an array by value?
>
>>> Why would anyone want to wrap an array in a struct and pass that by value?
>
>> Why answer a question with another question?
>
>> I've never promoted or suggested that one put an array in a struct
>> and pass it by value, I frankly think it would be a stupid thing to
>> do in a C program.
>
> It might make sense for a small array. You might have an rgb
> array dimensioned [3] instead of three separae variables.
> The dimension, I believe, has to be a compile time constant.
>
> -- glen

Heck, for RGB, just use a struct with three variables in it.

The dimensions of arrays *used* to have to be compile time
constants. Now they have a type of array declared in a function
that can have its size depend on an integer passed into the
function. (I forget what they call it... maybe a "dynamic array"
or something.)

--
+----------------------------------------+
| Charles and Francis Richmond |
| |
| plano dot net at aquaporin4 dot com |
+----------------------------------------+
From: Charles Richmond on
Joe Pfeiffer wrote:
> glen herrmannsfeldt <gah(a)ugcs.caltech.edu> writes:
>
>> In comp.arch.fpga Scott Lurndal <scott(a)slp53.sl.home> wrote:
>> (snip, someone wrote)
>>>>> Q? Why would anyone want to pass an array by value?
>>>> Why would anyone want to wrap an array in a struct and pass that by value?
>>
>>> Why answer a question with another question?
>>
>>> I've never promoted or suggested that one put an array in a struct
>>> and pass it by value, I frankly think it would be a stupid thing to
>>> do in a C program.
>> It might make sense for a small array. You might have an rgb
>> array dimensioned [3] instead of three separae variables.
>> The dimension, I believe, has to be a compile time constant.
>
> It doesn't. You can use malloc() to allocate an arbitrary-sized buffer,
> and then use array syntax to access elements of the buffer. You can
> also pass the address of the buffer, and use it like an array in the
> called procedure.
>
> Since C99, you can allocate an array with a variable number of elements
> like this:
>
> printf(" array size >> ");
> scanf("%d", &size);
>
> int awry[size];

But how about the second dimension, Joe??? Can you allocate:

int awry2[size][size];

--
+----------------------------------------+
| Charles and Francis Richmond |
| |
| plano dot net at aquaporin4 dot com |
+----------------------------------------+
From: glen herrmannsfeldt on
In comp.arch.fpga Charles Richmond <frizzle(a)tx.rr.com> wrote:
(snip)

> Heck, for RGB, just use a struct with three variables in it.

Well, the suggestion was an array in a struct. With an array
you can loop over it.

> The dimensions of arrays *used* to have to be compile time
> constants. Now they have a type of array declared in a function
> that can have its size depend on an integer passed into the
> function. (I forget what they call it... maybe a "dynamic array"
> or something.)

Yes, but can you do that for an array in a struct. If you
pass it in a function call, and it isn't the last argument, how
will the called routine know where the other arguments are?

I haven't done much with C99 yet.

-- glen

From: Ahem A Rivet's Shot on
On Wed, 24 Feb 2010 11:31:45 -0800 (PST)
Eric Chomko <pne.chomko(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

No, he's saying that C doesn't really implement an array type, the
var[offset] syntax is just syntactic sugar for *(var + offset) which is why
things like 3[x] work the same as x[3] in C.

--
Steve O'Hara-Smith | Directable Mirror Arrays
C:>WIN | A better way to focus the sun
The computer obeys and wins. | licences available see
You lose and Bill collects. | http://www.sohara.org/
From: Michael Wojcik on
Joe Pfeiffer wrote:
> glen herrmannsfeldt <gah(a)ugcs.caltech.edu> writes:
>> In comp.arch.fpga Scott Lurndal <scott(a)slp53.sl.home> wrote:
>>
>>> I've never promoted or suggested that one put an array in a struct
>>> and pass it by value, I frankly think it would be a stupid thing to
>>> do in a C program.
>> It might make sense for a small array. You might have an rgb
>> array dimensioned [3] instead of three separae variables.
>> The dimension, I believe, has to be a compile time constant.
>
> It doesn't. You can use malloc() to allocate an arbitrary-sized buffer,
> and then use array syntax to access elements of the buffer. You can
> also pass the address of the buffer, and use it like an array in the
> called procedure.

That doesn't work for a pass-by-value array, which is what we're
talking about here. You can only pass an array by value in C if it's
an array type that's a member of a struct (or union, which is just a
special case of struct).

--
Michael Wojcik
Micro Focus
Rhetoric & Writing, Michigan State University