[comp.edu] Joshua should learn some C

jug@itd.dsto.oz (Jim Grundy) (01/20/90)

From article <16773@joshua.athertn.Atherton.COM>, by joshua@athertn.Atherton.COM (Flame Bait):
> This is a reply to article <1248@oravax.UUCP> ian@oravax.odyssey.UUCP,
> written by Ian Sutherland.  Please look at that posting to see his bogus
> example.
> 
> Ian:  please learn C (and teach it to your proof system) before posting
> examples using it.  In your example temp is an automatic (or local)
> variable, while a and b are parameters passed into the function which
> contains temp.  There is no way in C for temp to be the same variable
> as either a or b.  If temp were a static or a global, there would be
> a problem.  Note that calling swap recursively will work fine given 
> your example.  

Try this (The dummy var has been added so that this procedure has the
		  same signature as the original swap and so a call to it will
		  take up the same stack space)

void GetAnAddressOffStack(AddressOnStack, dummy)
int *AddressOnStack, dummy;
{
	int TemporaryVariableOnTheStack;

	AddressOnStack = &TemporaryVariableOnTheStack;
}

main()
{
	int *AddressOnStack, x, dummy;

	GetAnAddressOffStack(AddressOnStack &dummy);
	x = 1;
	*AddressOnStack = 2;
	swap(&x, AddressOnStack);
	printf("&d, &d", x, *AddressOnStack);
}

Now when swap is called, it's local variable temp will have the same address
as the value contained its second parameter y.
The printf is going to give you "1, 1".

JIM

Truely falme bait is what his name suggests