Brain Teaser

Michael Condict condict at cs.vu.nl
Fri Apr 13 00:15:37 AEST 1990


In article <2039 at awdprime.UUCP> cs.utexas.edu!ibmchs!auschs!sanders.austin.ibm.com!sanders (Tony Sanders) writes:
|In article <10289 at wpi.wpi.edu> oesterle at wpi.wpi.edu (Shawn H. Oesterle) writes:
|-Example:
|-	{
|-		void * x, * y, * tmp;
|-
|-		tmp = x;
|-		x = y;
|-		y = x;
|-	}
|-	Make a piece of code which has the same effect as this, but without
|-	using the 'tmp' variable (in C, of course).
|This is really quite easy AND ANSI compliant.
|
|You see, to "make a piece of code which has the same effect" as your
|sample code, this will suffice:
|    void *x, *y;
|    x = y;
|
|If you don't believe me then double check your sample code.

Actually, the sample code can be optimized more than that.  It is exactly
equivalent to the following statement:

			;
		
since the variables are all local to the block.
--
Michael Condict		condict at cs.vu.nl
Vrije University
Amsterdam



More information about the Comp.lang.c mailing list