why does setjmp return 1 after longjmp(buf,0)?

Guy Harris guy at auspex.auspex.com
Tue Sep 18 09:10:59 AEST 1990


>I don't recall any, because it not only reflected existing practice,
>it also is obviously essential to prevent a longjmp from returning to
>the wrong branch of the setjmp return path.

Even if the person calling "longjmp" screws up and passes a zero
argument?  It would seem that the prevent this from happening by the
simple expedient of not screwing up....

>Every version of longjmp I can recall ever maintaining worked exactly
>that way.

The BSD one doesn't do that; however, a quick check of the V7 version
and the 32V version (from Berkeley's archives, no less) reveals that
they seem to have worked the same way as the S5 one, namely that passing
a return value of 0 is equivalent to passing a return value of 1.

So it looks as if Berkeley are the ones who went off the path, here. 
Fortunately, the ANSI C spec forbids that sort of thing, so 4.4BSD (and
systems that picked up this divergence and haven't yet removed it) will
probably get with the program....



More information about the Comp.std.c mailing list