Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c++
Subject: Re: two's complement idea
Date: Mon, 27 Jan 2020 02:20:54 -0800
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <86r1zlgpyx.fsf@linuxsc.com>
References: <4hBWF.107660$LY2.60603@fx23.am4> <20200125134202.8939b7b4f1db1e1f59c1411d@cvine--nospam--.freeserve.co.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="7c306968cf7022673062d49c54d79376"; logging-data="27743"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Cb5UiQNswDkY1QRZI0JEkdebGJftm3tU="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:6JNfS24O+RVCF3CRzwvsSNKOxn0= sha1:lTACDIVwIIb2R+c2rD3wFnUd7gA=
Xref: csiph.com comp.lang.c++:71621
Paavo Helde writes:
> On 25.01.2020 16:58, Bart wrote:
>
>> How would C++ help here, to avoid either that extra logic, or the use of
>> that goto? Here's the current outline (for_each_pwq is a macro expanding
>> to a regular for-header):
>>
>> L:
>> A;
>> for (...) {
>> B;
>> if (C) continue;
>> D;
>> goto L;
>> }
>
> This is an example of some pretty convoluted logic, not even because
> of 'goto', but rather because of multiple code execution paths (two
> non-default exit paths from inner loop body and no normal exit
> path). I would rewrite this along the lines:
>
> bool foobar(...) {
> for (...) {
> B;
> if (!C) {
> D;
> return false;
> }
> }
> return true;
> }
>
> while (true) {
> A;
> if (foobar(...)) {
> break;
> }
> }
To me this alternative is worse than the original. Just a
personal reaction. To give the peanut gallery something to hoot
about, and fya, the code (in C++!) may be recast as follows:
void
funky(){
A;
for (...) {
B;
if (C) continue;
D;
return funky();
}
}
(Let me say in advance I will disregard any sort of heated
discussion about the inadvisability of the self-recursion
here. I know a lot of people don't like it. Get over it.)