Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site rlgvax.UUCP Path: utzoo!linus!decvax!genrad!mit-eddie!godot!harvard!seismo!rlgvax!guy From: guy@rlgvax.UUCP (Guy Harris) Newsgroups: net.lang.c Subject: Re: Re: What is the setjump call Message-ID: <169@rlgvax.UUCP> Date: Sat, 6-Oct-84 02:55:09 EDT Article-I.D.: rlgvax.169 Posted: Sat Oct 6 02:55:09 1984 Date-Received: Sun, 7-Oct-84 21:50:01 EDT References: <2528@ihldt.UUCP> Organization: CCI Office Systems Group, Reston, VA Lines: 30 > 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