Clarification needed on Pointers/Arrays

Karl Heuer karl at haddock.ima.isc.com
Mon Mar 6 12:39:04 AEST 1989


In article <9766 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
>In article <11914 at haddock.ima.isc.com> karl at haddock (Karl Heuer) writes:
>>C has had struct copy for the last decade; I understand that array copy was
>>not added at the same time only because they couldn't find a clean way to
>>fit it into the existing language.  The invention of prototypes did provide
>>a (relatively) clean path, but unfortunately X3J11 didn't take it.
>
>Excuse me, but C array types were already too badly broken to be fixed
>by anything X3J11 could do.  Of course we could have devised a new
>language with arrays as first-class citizens, but it wouldn't be C.

I didn't say that X3J11 could have made arrays first-class citizens; I said
it could have added array copy (thus raising arrays from third-class citizens
to second-class, as was done with structs).  I believe something like this
would do it:

|If the left operand of the assignment operator has type `array [N] of T',
|then the right operand must have type `pointer to T' (possibly resulting from
|the decay of an array expression), and the first N elements of the array into
|which it points are copied.  This also applies to the implicit assignment of
|an actual argument to an array-typed formal argument (when a prototype is in
|scope), and to the implicit assignment caused by the `return' statement in an
|array-typed function.

As I noted in an earlier article (which seems to have expired now), one
problem with this is that array copy with a constant size is of limited
utility.  I agree that this cannot be fixed without inventing a new language.

Actually, I wasn't even expecting X3J11 to accept this untested feature; I
just wanted it to be a legally conforming extension.  Unfortunately, it now
collides with the kludge that allows "[]" to declare a pointer, in the special
case of a formal argument.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list