Re: why cant functions return arrays



On Apr 16, 4:56 am, jacob navia <ja...@xxxxxxxxxx> wrote:
John Bode wrote:

[snip]

I *suspect* the reason behind the OP's query is that array objects are
non-modifiable lvalues:

    int a[10], b[10];
    b = a;            /* illegal! */

Since you can't assign a new array value to an array type object, it
doesn't make sense to allow functions to return array types.  That
would make it not a mistake in design for no good reason (per Jacob),
but a consequence of how arrays are handled by the rest of the
language.  Whether "how arrays are handled by the rest of the
language" is a mistake in design or not is an open issue.

This is just the same for structures. They have to be the same size.

It would be the same for arrays, arrays would be needed to be the same
size.

But then, since size information is always discarded when passing an
array to a function, this would be difficult to achieve.

What I wanted to emphasize is that the whole handling of arrays
is completely crazy in C.

I think the problem was that its designers had seen Algol come to
grief as Algol runtimes strained to preserve structural information at
run time on storage sizes that were just too small, and for this
reason weren't about to store and pass dope vectors. In my compiler
for "build your own .net language and compiler" I had to do so since
Quick Basic had array subscripts that could start at any integer,
negative or positive. This is no longer the case for Visual Basic.

C is just out of date is all.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatiquehttp://www.cs.virginia.edu/~lcc-win32

.



Relevant Pages

  • Re: Design issue and Synthesis problem
    ... design too scalable and in that process, adding many arrays and thus ... assignments, but I cannot find any missing assignments. ... generates a multiplexer (and two adders). ...
    (comp.lang.verilog)
  • Re: Whats the deal with PSoC programmers?
    ... MCU with partially reconfigurable ... requiring processing of slowly varying analog signals. ... The reconfigurable arrays are loaded at reset time with configuration ... Cypress's design tools. ...
    (comp.arch.fpga)
  • Re: OOP and C++ and C (was Re: Dennis Ritchie -- An Appreciation)
    ... languages interfaces. ... at least) includes run-time polymorphism. ... Am I suddenly not doing object-oriented design? ... I find that typically my programs are structured as arrays of arrays ...
    (comp.lang.c)
  • Re: [9fans] A new language for Plan 9
    ... I'm aware of that quote. ... The design of bit arrays will be totally different from the design of bitfields. ... and then use getlong as follows: ...
    (comp.os.plan9)
  • Re: Copying rows in a two dimensional array.
    ... Arrays should have been allowed to have discriminants. ... missed in the language design. ... Early Ada 9x had discriminants for arrays. ...
    (comp.lang.ada)