From: (see below) on
On 25/02/2010 23:26, in article SGDhn.70229$Hk6.39325(a)news.usenetserver.com,
"Scott Lurndal" <scott(a)slp53.sl.home> wrote:

> "(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?

Why would anyone want to wrap an array in a struct and pass that by value?

--
Bill Findlay
<surname><forename> chez blueyonder.co.uk


From: Scott Lurndal on
"(see below)" <yaldnif.w(a)blueyonder.co.uk> writes:
>On 25/02/2010 23:26, in article SGDhn.70229$Hk6.39325(a)news.usenetserver.com,
>"Scott Lurndal" <scott(a)slp53.sl.home> wrote:
>
>> "(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?
>
>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.

I was curious if anyone thought passing an array by value was a
_good_ idea.

scott

From: glen herrmannsfeldt on
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
From: Joe Pfeiffer on
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];
--
As we enjoy great advantages from the inventions of others, we should
be glad of an opportunity to serve others by any invention of ours;
and this we should do freely and generously. (Benjamin Franklin)
From: Charles Richmond on
glen herrmannsfeldt wrote:
>
> [snip...] [snip...] [snip...]
>
>> As Al Stewart once sang, "I was jumping to conclusions, and one of them
>> jumped back."
>

"If you stare into the Abyss long enough,
the Abyss stares back at you."

-- Friedrich Nietzsche

--
+----------------------------------------+
| Charles and Francis Richmond |
| |
| plano dot net at aquaporin4 dot com |
+----------------------------------------+