Why pass structs? (not struct pointers)

decot at hpisod2.UUCP decot at hpisod2.UUCP
Tue Mar 3 06:40:47 AEST 1987

> 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

More information about the Comp.lang.c mailing list