Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Sort of trivial code challenge - may be interesting to you anyway Date: Fri, 06 Mar 2026 08:53:25 -0800 Organization: A noiseless patient Spider Lines: 48 Message-ID: <865x78c322.fsf@linuxsc.com> References: <10n80sc$3soe4$1@dont-email.me> <86v7feei2e.fsf@linuxsc.com> <10o53k6$1i0ef$2@dont-email.me> <86ms0peby6.fsf@linuxsc.com> <10ockdh$3qpk6$1@dont-email.me> <10ocrjn$3qpk6$2@dont-email.me> <10od64s$3qpk6$4@dont-email.me> <86ikb9bmtw.fsf@linuxsc.com> <10oem5t$n5hk$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Fri, 06 Mar 2026 16:53:29 +0000 (UTC) Injection-Info: dont-email.me; posting-host="b0f5cdf16a02d5dcd9e415cfd7cb6e85"; logging-data="864636"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18TO+cWZqQyXMKG7PQHUqCQi3g8UVmCojA=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:M3ArHdNx2sRrOtc15bsyL6k7dqM= sha1:YmBB1ji6o+UhhzDKVQLmO+8w8qw= Xref: csiph.com comp.lang.c:396827 Lew Pitcher writes: > On Thu, 05 Mar 2026 20:31:39 -0800, Tim Rentsch wrote: > >> Lew Pitcher writes: >> >>> OK, it's not pretty, but here it is >> >> No worries - being pretty is not on the list of requested properties. :) >> >> Congratulations on being the first to post an answer. >> >> Two problems related to how setjmp()/longjmp() are used: >> >> 1. Any local variable changed between a setjmp() and the longjmp() >> that goes back to it must be declared 'volatile' to avoid problems >> with indeterminate values. (Minor.) >> >> 2. A pattern like 'x = setjmp( jbuf );' is not one of the officially >> approved forms in the C standard for setjmp(). More specifically, >> any such usage has undefined behavior. (More serious.) >> >> If you look in the C standard for setjmp(), there is a subsection >> titled 'Environmental limits' that explains which forms are approved >> for use. Personally I think it's regrettable that 'x = setjmp( jbuf );' >> is not one of them, but I feel obliged to observe that limitation and >> follow what the standard prescribes for using setjmp(). > > yah. > > As you can tell, I haven't used setjmp()/longjmp() much, and am > unfamiliar with the caveats surrounding them. I became aware of the restrictions some time ago, after seeing discussion in comp.lang.c. After that I looked carefully at the C standard to learn the official rules. > I'll look at revising my code, in the light of your comments, and > repost with a more "legal" version. Great, I'm cheering you on. :) > Thanks for the observations. I look forward to seeing /your/ code :-) I'm eager to post it. I'm still hoping DFS will at least post an attempt. I'm happy to give a hint if someone asks. Let's say I will wait another day or so and can post after that whether or not DFS has come forward.