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

Don Libes libes at cme.nist.gov
Sun Sep 16 03:07:26 AEST 1990


After being bitten by this, I thought about it awhile and I still find
it odd.  "Portability and the C Language" [Jaeschke] says this is:

	"so that a call to setjmp directly (which returns 0) cannot
	be confused with longjmp's returning through setjmp with a
	value of 0."

I think it's more confusing this way.

If a programmer doesn't want to be confused with setjmp's original
call, then isn't the obvious solution to choose a different value than
0?  Why would someone explicitly say longjmp(buf,0) rather than
longjmp(buf,1)?  It surely can't be for readability!

Has any of you personally ever intentionally written longjmp(buf,0)
knowing that it would return 1?  Or did this become Standard because
of "existing practice" and the thought that it would break working
programs?  (I suspect it would probably fix more programs.)

Was there any discussion about "fixing" this?  I have some old UNIX
manuals that document setjmp returning whatever longjmp says, no
questions asked.  When did this "feature" creep in?

Don Libes          libes at cme.nist.gov      ...!uunet!cme-durer!libes

Oh, and as long as I'm getting my burning questions answered, what
does PJ stand for?



More information about the Comp.std.c mailing list