Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!sri-unix!hplabs!hpcea!hpda!hpirs!hpisod2!decot From: decot@hpisod2.UUCP Newsgroups: comp.lang.c Subject: Re: Why pass structs? (not struct pointers) Message-ID: <2550006@hpisod2.HP.COM> Date: Mon, 2-Mar-87 15:40:47 EST Article-I.D.: hpisod2.2550006 Posted: Mon Mar 2 15:40:47 1987 Date-Received: Thu, 5-Mar-87 20:33:55 EST References: <3346@cisunx.UUCP> Lines: 51 > Mostly because it seemed that it would be silly not to. You can > push and return any other data type (well almost any other, unions > still don't work mostly). The only reason STRUCTS were initially > left out was because they weren't easy to do. Arrays were also left out. The only type of thing you still can't assign, pass, or return. Silly. And arrays are just as easy as structs to manipulate. It's just that it's difficult to find an inutitive syntax for array lvalues since the only reasonable one was foolishly grabbed to mean "no, you see, when it's an array name, it's really a pointer to the first element of the array, not the array itself, so that it looks sort of like you can pass arrays by value". Therefore, here's what I consider to be the next best syntax available for specifying array lvalues: identifier [] This refers to the entire array whose name is identifier. It is an invalid construction where the size of the array is not known. #define ARRSIZ 20 main () { int (reverse())[ARRSIZ]; /* function returning array [ARRSIZ] of int */ int arr[ARRSIZ] = "this is amazing"; arr[] = reverse(arr[]); printf("%s\n", arr); } int (reverse(s))[ARRSIZ] char s[ARRSIZ]; { char tmp[ARRSIZ], *tp = tmp; int i; for (i = strlen(s)-1; i >= 0; i--) *tp++ = s[i]; *tp = '\0'; return tmp[]; } Dave Decot hpda!decot