Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!motcsd!xdos!doug From: doug@xdos.UUCP (Doug Merritt) Newsgroups: comp.sys.amiga.tech Subject: Re: M2/C discussion (Re: Can you nest subroutines in C?) Summary: Answer to "why longjmp/setjmp in C?" Message-ID: <413@xdos.UUCP> Date: 5 Jul 89 14:41:12 GMT References: <4524@crash.cts.com> <18213@usc.edu> <8673@pyr.gatech.EDU> Reply-To: doug@xdos.UUCP (Doug Merritt) Organization: Hunter Systems, Mountain View CA (Silicon Valley) Lines: 36 In article <8673@pyr.gatech.EDU> dsking@pyr.UUCP ( David King) writes: > setjmp/longjmp? Its definately not part of the language definition >(they actually aren't part of C's definition unless the ANSI committee added >it in the last year), Surprising; I was also surprised when I failed to find them in K&R just now. > *jmp actually are library routines on UNIX that got used in >programs so much that they made it into most C systems. Well, the fact that they're library routines is irrelevent. There are a fair number of library routines that are a standard part of the definition of the C language, including e.g. printf() and strlen(). It's part of the charm of C that i/o and string handling "builtins" are first class citizens in this way. >something I've been wondering - what are things like *jmp useful for in an >Amiga program? The cleanest, most defensible use is as a non-local goto to unwind from deep procedures as part of error recovery. Even the purist Niklaus Wirth uses (and advocates) non-local goto's for this purpose. Without setjmp/longjmp, C has no non-local goto at all, and loses this ability. Makes severe-error handling routines in complex software very messy. That's why I surprised they're not in the standard. They're also defined cleanly enough that it's hard to imagine a modern day general purpose cpu that would have trouble allowing their implementation, so I wonder why they didn't get included. Hmmm...perhaps something like a Z8000 with different address spaces for data and stack? I'm not really awake yet, anybody know? Doug -- Doug Merritt {pyramid,apple}!xdos!doug Member, Crusaders for a Better Tomorrow Professional Wildeyed Visionary