Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!seismo!mcvax!ukc!eagle!icdoc!cam-cl!am From: am@cam-cl.UUCP Newsgroups: comp.lang.c Subject: Re: Some questions about ANSI C Message-ID: <1043@jenny.cl.cam.ac.uk> Date: Fri, 14-Aug-87 07:38:02 EDT Article-I.D.: jenny.1043 Posted: Fri Aug 14 07:38:02 1987 Date-Received: Sun, 16-Aug-87 18:41:03 EDT References: <497@houxs.UUCP> <165600007@uiucdcsb> Reply-To: am@cl.cam.ac.uk (Alan Mycroft) Organization: U of Cambridge Comp Lab, UK Lines: 42 In article <165600007@uiucdcsb> kenny@uiucdcsb.cs.uiuc.edu (asking for justifications and the like of Doug Gwyn's list of ANSI changes) writes: >> Setjmp must be a macro. >Does this really translate to ``Setjmp need not exist as a library >function, but may be implemented in macro form only?'' Requiring the >implementor to include something like > extern int _Setjmp_ (jmp_buf); > #define setjmp(jb) (_Setjmp_((jb))) >in seems just a trifle silly. > I agree Doug's original wording was odd (the wording for assert whcih has similar properties seems better) but... I would exactly like to see the above _Setjmp_ oddity present in for the following reasons: 1. The above setjmp causes all occurences of setjmp NOT IN FUNCTION CONTEXT to be faulted. E.g. main() { foo(setjmp); } would produce the message 'undeclared variable setjmp' which thereby polices the standard better than alternatives. 2. As support for why I wish to inhibit such strange calls (partly out of pure legalistic malice, but also:) Consider the function: void oddity(int f(jmp_buf)) { static jmp_buf t; if (f(t)) g(f); else h(f); } An optimisiation for such functions is to do tail recursion removal I.e. treat the code for oddity as This is really quite a useful optimisation, saving code space, stack space and time. Exact validity conditions need to be considered well! Now, the punchline: if f() in the above could be setjmp, and it were legal to call it via such a mechanism (e.g. as permitted by Oct 86 draft) then I cannot do this optimisation. (The stack-frame for oddity would be overwritten by the call to h() and the attempt to restore it in longjump would fail catastrophically). The 'solution' used in our compiler is to disable tail-recursion optimisation if a call to setjmp or a variable function occurs, but therefore I'm very happy to see this ANSI change.