What should be added to C

aglew at ccvaxa.UUCP aglew at ccvaxa.UUCP
Fri May 23 00:39:00 AEST 1986


>/* Written  8:04 pm  May 16, 1986 by franka at mmintl.UUCP in ccvaxa:net.lang.c */
>/* ---------- "Re: What should be added to C" ---------- */
>Something which got forgotten in my original article: I would favor an
>exchange operator.  This one is quite frequently useful, and the
>alternatives are ugly.
>
>Frank Adams                           ihnp4!philabs!pwa-b!mmintl!franka
>Multimate International    52 Oakland Ave North    E. Hartford, CT 06108
>/* End of text from ccvaxa:net.lang.c */

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.

#define swap(a,b)  a,b := b,a

does the exchange without having to type the name twice.

Andy "Krazy" Glew. Gould CSD-Urbana.    USEnet:  ihnp4!uiucdcs!ccvaxa!aglew
1101 E. University, Urbana, IL 61801    ARPAnet: aglew at gswd-vms



More information about the Comp.lang.c mailing list