Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!samsung!munnari.oz.au!metro!usage.csd.unsw.oz.au!spectrum!cameron From: cameron@usage.csd.oz (Cameron Simpson) Newsgroups: comp.lang.c Subject: Re: Ambiguity in definition of setjmp/longjmp makes them much less useful Message-ID: <891@usage.csd.unsw.oz.au> Date: 9 Oct 90 03:36:36 GMT References: Sender: news@usage.csd.unsw.oz.au Reply-To: cameron@spectrum.cs.unsw.oz.au (Cameron Simpson) Organization: none Lines: 40 From article , by tom@ssd.csd.harris.com (Tom Horsley): | Personally, I believe that compilers should support setjmp() as a special | construct - simply making might-goto arcs from every other function call to | a point immediately following any setjmp() calls would add enough | information to the flow graph for an optimizing compiler to recognize the | funny lifetimes that registers might have and volatile would only be needed | for variables that interact with signal handling code (since a signal | can happen anywhere in the program, not just at a function call). But think about what happens when you write sigfn(sig) { longjmp(foojmpbuf,1); /*NOTREACHED*/ } Since, as you say, a signal can happen anywhere then there is now a might-goto arc from _every_ point in the program which can conceivably be called from within any function which uses foojmpbuf as a jump buffer. This could easily include large stretches of the C library. It gets much worse if something as bizarre as the following is done: jmp_buf *current_restore_point=NULL; sigfn(sig) { if (current_restore_point == NULL) fprintf(stderr,"ouch! - uncaught signal %d\n",sig); else longjmp(*current_restore_point,sig); } And then set/clear current_restore_point around various bits of code. This puts might-goto arcs from almost every bit of code unless your compiler is almost precognitive, and the programmer aware of this effect. My preferred solution is not to use setjmp/longjmp at all. Of course, it isn't always possible. BSD's non-switch-off-able restartable system calls (like a read from a tty) irk me particularly in this regard. - Cameron Simpson cameron@spectrum.cs.unsw.oz.au "If it can't be turned off, it's not a feature." Karl Huer (I think).