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: Thu, 05 Mar 2026 20:31:39 -0800
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <86ikb9bmtw.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>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Fri, 06 Mar 2026 04:31:43 +0000 (UTC)
Injection-Info: dont-email.me; posting-host="b0f5cdf16a02d5dcd9e415cfd7cb6e85"; logging-data="405301"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/xbzDfSwluzeXLdMxN0KorubbB0fMrJow="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:dgXWaEZejhA9VCU9uuvBeudZ3H0= sha1:lM6YZAMt91MW2OYJkmQWPWDhT+o=
Xref: csiph.com comp.lang.c:396811
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().