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: Wed, 11 Mar 2026 10:44:50 -0700
Organization: A noiseless patient Spider
Lines: 59
Message-ID: <86qzpq8dm5.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> <10ohqc1$1m7c1$3@dont-email.me> <86seab9zz2.fsf@linuxsc.com> <10oi0n0$1m7c1$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Wed, 11 Mar 2026 17:44:58 +0000 (UTC)
Injection-Info: dont-email.me; posting-host="5f44bcdbc02769ce6998caa4a4cb2206"; logging-data="1387857"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/zYyIZBo+g5rWUPwh7pSxg7tr0If4tWRU="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:gWie/xC6Ks471qzxVBNju5S5Qcg= sha1:xiBe9tonzfBSRtlmOZVbJySTI3c=
Xref: csiph.com comp.lang.c:396909
Lew Pitcher writes:
> On Sat, 07 Mar 2026 11:55:13 -0800, Tim Rentsch wrote:
>
>> Lew Pitcher writes:
>>
>>> On Fri, 06 Mar 2026 13:51:58 +0000, Lew Pitcher wrote:
>>
>> [...]
>>
>>>> I'll look at revising my code, in the light of your comments, and
>>>> repost with a more "legal" version.
>>>
>>> And, here it is
>>> [...]
>>
>> First of two responses
>>
>> 1. I think your error checking is more thorough than what I did.
>> I do check that inputs are well formed but it's possible that
>> out of range values will give inappropriate results.
>>
>> 2. I don't have any error return. I do diagnose various conditions
>> (and in particular the no-square-possible cutoff values) but don't
>> bother with status. It would be easy to add but I didn't do it. :)
>>
>> 3. How setjmp() is used is still out of bounds. The rule for setjmp()
>> in a switch() is the setjmp() must be the entire expression that is
>> switched on. Effectively longjmp() can pass only constant values,
>> because there is no way to do anything with the value except see if
>> it is true or false (in an if()) or match it against 'case' labels.
>
> You (and the standards) are a hard task-master :-)
The C standard does need an attention to detail in many cases.
Personally I think that is a plus as well as being a minus in
some ways - being forced to pay attention to detail often helps
clarify my thinking.
> Corrected version follows
>
[...]
I appreciate the effort. I was surprised by the use of
setjmp() to simulate loops; probably I shouldn't have
been but it hadn't occurred to me before now. Then again
I have been used to functional programming techniques for
more than 20 years now so loops feel less natural to me
now than they used to.
One point that confused me for a while was the lack of a
'break' before the initial 'case 3:'. At first I thought
it was just an oversight that it wasn't there. Of course
it was deliberate, and I saw what you were doing. My code
accepts and allows a cutoff of 0, which may have added to
my confusion. Your code could do that by using a different
value for the "no cutoff entered" condition.
I may have other general comments later.