Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!mhuxm!mhuxf!mhuxi!mhuhk!mhuxt!houxm!ihnp4!bentley!kwh From: kwh@bentley.UUCP (KW Heuer) Newsgroups: net.lang.c Subject: Re: More extensions to C Message-ID: <856@bentley.UUCP> Date: Mon, 26-May-86 15:34:12 EDT Article-I.D.: bentley.856 Posted: Mon May 26 15:34:12 1986 Date-Received: Wed, 28-May-86 01:49:53 EDT References: <1483@mmintl.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner Lines: 32 In article <1483@mmintl.UUCP> mmintl!franka (Frank Adams) writes: >In article <826@bentley.UUCP> kwh@bentley.UUCP writes: >>[Swap] could be considered a special case of my ",," operator: to exchange >>x and y, write "x = (y ,, (y = x))". > >I would prefer a syntax like "{x, y} = {y, x};" It's more readable. Yes, for a swap. The real power of ",," is for removing explicit temporary once-only variables in general; for example, it allows the function int pop() { int temp1; struct stack *temp2; temp1 = stk->top; temp2 = stk->next; free(stk); stk = temp2; return (temp1); } to be abbreviated to the macro #define pop() (stk->top,,(stk=(stk->next,,free(stk)))) (A sort of generalization of the postfix operators. "++x" means "x=x+1", but "x++" means "x,,(x=x+1)".) >(BTW, a really good optimizing compiler can optimize out the temporary. I'm >not fully up on what optimizers are doing these days, but I doubt that there >are many compilers which do this. Optimizing it out is easier if it is >declared locally ("{int temp = x; x = y; y = temp;}") instead of being >declared at the top of the routine.) Unfortunately, I think the "clue" gets lost before the optimizing phase. Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint