Bug iwith setjmp/longjmp on Vax

Henry Spencer henry at utzoo.UUCP
Sat Jun 8 03:10:47 AEST 1985


> This program was compiled under 4.2BSD on a VAX; it doesn't work the way it
> should (I get a 'longjmp botch' message).  If I compile the same exact
> program on a Sun running 4.2BSD it works fine.  I know that setjmp() and
> longjmp() work on a Vax, but why is this simple program giving me a problem?
> ...
> main(){
> 	foo();
> 	longjmp(env, 1);
> }
> 
> foo(){
>   mode = setjmp(env);
>   ...
> }

To quote the 4.2BSD setjmp(3) manual page (as well as all previous setjmp
manual pages):

	[longjmp] returns in such a way that execution continues as
	if the call of setjmp had jsut returned ... to the function
	that invoked setjmp, *which must not itself have returned in
	the interim*.  [emphasis added]

In other words, your code is wrong.  Put the setjmp in main(), or the
longjmp in foo(), and it will be correct.  It is only accidental that
it works on some machines as it is.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry



More information about the Comp.unix.wizards mailing list