Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site gatech.UUCP Path: utzoo!linus!decvax!harpo!gummo!whuxlb!pyuxll!eisx!npoiv!npois!hogpc!houxm!ihnp4!we13!burl!akgua!sb1!sb6!emory!gatech!arnold From: arnold@gatech.UUCP Newsgroups: net.lang.c Subject: Re: mixing pointers and arrays (arrays by value) Message-ID: <378@gatech.UUCP> Date: Wed, 17-Aug-83 10:20:06 EDT Article-I.D.: gatech.378 Posted: Wed Aug 17 10:20:06 1983 Date-Received: Thu, 18-Aug-83 12:42:44 EDT References: <1742@allegra.UUCP> Organization: Georgia Tech, School of ICS Lines: 61 I think the way to change C to copy arrays by value is to add a new operator to the language. I suggest using the ` (back quote). This is one of 3 characters which are not used in C at all (others are $ and @). It would work something like this: char x[10],y[10]; /* declaration of two arrays */ `x = `y; /* copy array y to array x, equivalent to strcpy(x,y) */ foo(`y); /* call procedure foo() with the entire array y sent by value */ A procedure receiving an array passed by value would declare it as follows: foo(array) char `array[]; /* the [] says 'array', the ` says it is passed by value */ { /* code */ } So far, this would allow array assignment, without changing the meaning of 'array name as pointer to first element'. It is also upward compatible, and would not break any existing programs. The use of an explicit operator makes it 100% clear that array operations are going on. The only problem with this is assignment of character strings; one would have to do something ugly like: `x = ` "string constant"; however, the language could probably special-case it to make the ` before the constant un-necessary, the same way that it special-cases initialization of character arrays to allow using "string" instead of the more verbose { 's', 't', 'r', 'i', 'n', 'g', '\0' }. As with initialization, where the braces form is allowed, the ` in front of a string constant would also be valid (i.e. no error messages), just not necessary. An array concatenation operator, probably $, might also be useful. For example: #define DIM /* whatever */ char x[DIM], y[DIM], z[DIM]; x = y $ z; /* same as sprintf(x, "%s%s", y, z) */ x $= y; /* the more common strcat(x,y); */ Both the ` and the $ should work for arrays of any type, not just character arrays, but character arrays would be where they were the most useful. They should not work for arrays of mixed type. New operators would make it easy for lint to catch mistakes as well, for instance strcat(x, `y) would be a type error, an array passed instead of a pointer. C could use some extensions for dealing with arrays, we just have to be *very* careful about how well they fit in with the rest of the language. -- Arnold Robbins Arnold @ GATech (CS Net) Arnold.GaTech @ UDel-Relay (ARPA) ...!{sb1, allegra}!gatech!arnold (uucp) ...!decvax!cornell!allegra!gatech!arnold