Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!decvax!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Clarification needed on Pointers/Arrays Message-ID: <11950@haddock.ima.isc.com> Date: 6 Mar 89 02:39:04 GMT References: <1436@etive.ed.ac.uk> <889@acf3.NYU.EDU> <11840@haddock.ima.isc.com> <890@acf3.NYU.EDU> <11914@haddock.ima.isc.com> <9766@smoke.BRL.MIL> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 34 In article <9766@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes: >In article <11914@haddock.ima.isc.com> karl@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@haddock.isc.com), The Walking Lint