Article View: comp.ai
Article #1233Re: Reasons why you don't prove your programs are correct
From: Jim Grundy
Date: Fri, 19 Jan 1990 20:29
Date: Fri, 19 Jan 1990 20:29
43 lines
2010 bytes
2010 bytes
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
Technical Details
Message-ID:
<578@fang.dsto.oz>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!bloom-beacon!bu.edu!bu-cs!snorkelwacker!usc!elroy.jpl.nasa.gov!ames!uhccux!munnari.oz.au!sirius.ucs.adelaide.edu.au!fang!jugReferences:
<16773@joshua.athertn.Atherton.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!bloom-beacon!bu.edu!bu-cs!snorkelwacker!usc!elroy.jpl.nasa.gov!ames!uhccux!munnari.oz.au!sirius.ucs.adelaide.edu.au!fang!jug From: jug@itd.dsto.oz (Jim Grundy) Newsgroups: comp.ai,comp.edu,comp.object Subject: Re: Reasons why you don't prove your programs are correct Message-ID: <578@fang.dsto.oz> Date: 19 Jan 90 20:29:34 GMT References: <16773@joshua.athertn.Atherton.COM> Sender: news@fang.dsto.oz Reply-To: jug@itd.dsto.oz Lines: 43