Anti-decay operator, again (postscript to previous message)

queueing-rmail uunet!lupine!segfault!rfg
Tue Dec 8 22:12:37 PST 1992


This note is just a follow-up to my preceding lengthy message about my
idea for adding an "anti-type-decay" operator `[]' to C so that we could
actually manipulate arrays as arrays (without breaking any existing code).

In that message, I erroneously suggested that a two-dimensional array (in C)
would undergo two separate stages of type decay.  Silly me!  Of course,
that is untrue.  It only undergos one such "type decay" stage, so that:

		int array[10][20];
		int (*p)[20];

		void foobar ()
		{
			p = array;
		}

works just fine (in ANSI C anyway).

That fact actually simplifies the idea I had.  Now, if we wanted to add two
matricies together to produce a third, we could just use one postfix `[]'
anti-type-decay operator following each of the operands involved, as in:

		int sink[10][20]
		int src1[10][20];
		int src2[10][20];

		void mat_add ()
		{
			sink[] = src1[] + src2[];
		}

Note that although I didn't say so in my prior message, this assumes that
the semantics associated with most normal operators (e.g. `=' and `+')
would simply be extended (in a natural way) from operands of dimensionality
zero to operands whose type are of higher dimension.  (The exception of
course is the comparison operators, which I talked about at length in my
preceding message.)

I should also offer one other clarification relative to my preceding posting.
In that message, I pooh-poohed the idea of adding any sort of "array slicing"
feature to C.  I should note however that the same effect could be achieved
via judicious use of the proposed anti-type-decay operator `[]' and the
"array cast" feature which I also talked about in my prior message.

For example, to slice 5 elements out of the array `a' starting at the i'th
element, we would just write:

			(int[5]) (&a[i])[]

Note that the `[]' operator would (in effect) have higher precedence
(syntactically) than the cast (just as [n] now does) so that would parse as:

			(int[5]) ((&a[i])[])

We could likewise slice out a `j' long sequence of the elements of `a'
starting at the i'th index via:

			(int[j]) (&a[i])[]

or alternatively:

			(int[j]) (a+i)[]

.. thus applying the "dynamic array cast" feature which I also discussed
in my prior message.

I just thought that I should clarify these two important points.


// Ron ("Loose Cannon") Guilmette
// uucp: ...uunet!lupine!segfault!rfg
// X3J16:  Deadline?  What deadline?



More information about the Numeric-interest mailing list