What is the setjump call

Guy Harris guy at rlgvax.UUCP
Fri Oct 19 08:13:22 AEST 1984


> > Actually, the fact that longjmp works with one argument is not an
> > accident.  The SVR2 manual page for setjmp states, "If longjmp is
> > invoked with a second argument of 0, setjmp will return 1."  This
> > was done to make the two argument version of setjmp backward com-
> > patable with the one argument version.
> 
> It's still an accident.  Calling a function (e.g. longjmp) with fewer
> parameters than expected is **NOT** guaranteed to make the missing
> parameters look like zeros.  This may work on some machines, but it
> is not portable.

Well, one could argue that if all one cares about is whether "setjmp"
returns a 0 (normal return) or non-zero (nonlocal goto) value, then calling
"longjmp" with only one argument will work under all circumstances (either
the non-existent argument gets a zero value by accident, in which case it
gets mapped into 1, or it gets a non-zero value by accident, in which case
it is non-zero).  However, it's still not guaranteed to work everywhere.
(Admittedly, there are a few functions in the C library that take a
variable number of arguments, like "printf" and the "open" system call in
USDL UNIX and in 4.2BSD; however, whether the extra arguments are present
or not can be intuited from the values of the required arguments, and the
code can avoid touching the extra arguments if they are missing.  This is
emphatically not the case for "longjmp".  There may be implementations of
C in which not touching the missing arguments may not be enough; these
implementations may special-case "printf", but not "setjmp" or "longjmp" -
or "open", for that matter.)

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



More information about the Comp.lang.c mailing list