Article View: gnu.gcc.help
Article #54439Help with setjmp
From: John Franco
Date: Sun, 28 Oct 1990 21:59
Date: Sun, 28 Oct 1990 21:59
56 lines
2208 bytes
2208 bytes
I am having a problem with understanding setjmp in gcc (and some other C
compilers for that matter). The following code prints different addresses
for p (until some resource is exhausted):
#include <setjmp.h>
jmp_buf env1, env2;
main()
{ if (setjmp(env1)) f1(); else f2(); }
int f1()
{ if (setjmp(env1) == 0) longjmp(env2,1); else f1(); }
int f2()
{ int p;
printf("\n%d",&p);
if (setjmp(env2) == 0) longjmp(env1,1); else f2();
}
However, the apparently slight change in f1 of using a goto instead of a
recursive call to f1, as in the code below, causes the setjmp to fail to
work as in the previous example. The result is an error message of the
type "longjmp botched" after only one address is printed. The code below
does not seem to violate any setjmp conditions that I know about. Help
leading to an understanding of what is happening is gratefully appreciated.
Please email to john.franco@uc.edu
#include <setjmp.h>
jmp_buf env1, env2;
main()
{ if (setjmp(env1)) f1(); else f2(); }
int f1()
{
ff: if (setjmp(env1) == 0) longjmp(env2,1); else goto ff;
}
int f2()
{ int p;
printf("%d\n",&p);
if (setjmp(env2) == 0) longjmp(env1,1); else f2();
}
For the interested reader: I am trying to figure out the relationship between
setjmp and call/cc of Scheme.
Thank you,
John Franco
Computer Science Department
University of Cincinnati
Technical Details
Message-ID:
<68007@iuvax.cs.indiana.edu>Path:
arc1-ca.pugleaf.net!gmdzi!unido!isaak!escher!nadia!smurf!ira.uka.de!sol.ctr.columbia.edu!samsung!cs.utexas.edu!tut.cis.ohio-state.edu!att!iuvax!francoShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,fa786f5e3f3d2a8f,start X-Google-Attributes: gid11318c,public X-Google-ArrivalTime: 1990-10-28 13:59:30 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!isaak!escher!nadia!smurf!ira.uka.de!sol.ctr.columbia.edu!samsung!cs.utexas.edu!tut.cis.ohio-state.edu!att!iuvax!franco From: franco@iuvax.cs.indiana.edu (John Franco) Newsgroups: gnu.gcc.help Subject: Help with setjmp Message-ID: <68007@iuvax.cs.indiana.edu> Date: 28 Oct 90 21:59:30 GMT Distribution: gnu.gcc.help Organization: University of Cincinnati Lines: 56 Posted: Sun Oct 28 22:59:30 1990