What is the setjump call

Guy Harris guy at rlgvax.UUCP
Sat Oct 6 16:55:09 AEST 1984


> 			longjmp(jb);
	.
	.
	.
> 		bar() { longjmp(jb); }

While we're on the subject of proper use of "longjmp", please note that
"longjmp" takes two arguments, not 1.  The second argument is the "return
value" that the "longjmp"ed-to "setjmp" should "return" when it's "longjmp"ed
to; if control is coming out of the "setjmp" from a regular call, it returns
0.

The "libPW" library on System V Release 2 (and, presumably, all earlier
versions) calls "longjmp" with only one argument; this works (I presume)
on System V on the VAX-11 by sheer accident, as there must have been a non-zero
value on the stack at the point where "longjmp" expected its argument.
It does *not* work on 4.2BSD, as there can happen to be a zero value on the
stack at that point.  Furthermore, there is no guarantee that it will work
on any other implementation of UNIX, or any non-UNIX C implementation.

Moral: run your code through "lint" whenever you can.  It will yell and scream
if you call a routine with the wrong number of arguments (unless you say
the routine can optionally take more than a given number, in which case it
will check only the required arguments.)  It looks like the S5R2 "lint" will
even check calls to "printf"!  (There's a new "lint" declaration "PRINTFLIKE"
which can be used for any routine that takes a "printf" string as an
formatting string and has a "printf"-like calling sequence.)

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy



More information about the Comp.lang.c mailing list