Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!ucla-cs!zen!ucbvax!decvax!ima!haddock!karl From: karl@haddock.UUCP Newsgroups: comp.lang.c Subject: Array primitives (was: *\"LDA\" ok?) Message-ID: <1036@haddock.ISC.COM> Date: Tue, 1-Sep-87 12:45:08 EDT Article-I.D.: haddock.1036 Posted: Tue Sep 1 12:45:08 1987 Date-Received: Wed, 2-Sep-87 07:22:39 EDT References: <8877@brl-adm.ARPA> <8088@mimsy.UUCP> <87@splut.UUCP> <2211@emory.uucp> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 29 In article <2211@emory.uucp> arnold@emory.UUCP (Arnold D. Robbins {EUCC}) writes: >[Suggests a new symbol "`" to represent arrays manipulated by value] If ANSI can be convinced not to repeat a certain K&R mistake, most of the cases you describe could be written without the new punctuator. To pass an array by value and/or return one: char foo(char arg[INSIZE])[OUTSIZE]; Once the prototype is in scope, "a1 = foo(a2)" can be interpreted properly. The array copy operation, "a1 = a2", is best handled by amending the array-to- -pointer conversion rule so that it does not attempt to convert "a2" in this context. (Note that this depends on "a1" being an array, not a pointer.) As has already been pointed out, most array manipulation in C at present is done via pointers instead. For fixed-length arrays this is not a problem; after "p = (int *)malloc(100 * sizeof(int));" one could copy the entire array by naming it "*(int (*)[100])p". (Better yet, one could make p a pointer to array in the first place: "p = (int (*)[100])malloc(sizeof(int[100]));" ... "*p".) Variable-sized arrays are trickier. I don't think it's appropriate to make "array of char" a magic synonym for "NUL-terminated string"; that partially solves one special case rather than the general problem. It smacks of PASCAL kludgery. The general problem of variable-sized arrays probably does require a new punctuator. I have an idea on this, too, but it needs more refinement. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint