What should be added to C

Andrew Koenig ark at alice.UucP
Sun May 25 16:24:33 AEST 1986


> Why not go all the way and implement Dijkstra's concurrent assignment?

>    i,j := j,i

> for a swap. Course, couldn't use commas, but you get the idea. 
> Compilers can generate good code for this, and it makes programs with
> complicated pointer manipulations much clearer; I used to teach it, and the
> associated code generation algorithm, to U1s in classes I TAed, and it
> greatly reduced the noise level of assignments in the wrong order.

Two comments:

	1. This is really not the same as a swap.  I would like
	   to be able to say something like

		swap (a[i++], a[j++]);

	   and have it do the right thing, effectively

		a[i],a[j] = a[j],a[i];
		i++, j++;

	   This is definitely not equivalent to

		a[i++], a[j++] = a[j++], a[i++];

	2. Can you give me a simple code generation algorithm
	   for multiple assignments that gets things like

		i, a[i] = j, a[j];

	   correct and never uses extra temporaries?  I have this
	   nagging feeling that even without subscripted variables,
	   the problem is NP-complete.



More information about the Comp.lang.c mailing list