Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Vulcans never bluff. -- Spock, "The Doomsday Machine", stardate 4202.1


devel / comp.lang.c / Re: How to avoid an overflow during multiplication?

SubjectAuthor
* How to avoid an overflow during multiplication?Mateusz Viste
+* Re: How to avoid an overflow during multiplication?Stefan Ram
|`- Re: How to avoid an overflow during multiplication?Ben Bacarisse
+* Re: How to avoid an overflow during multiplication?Ben Bacarisse
|`* Re: How to avoid an overflow during multiplication?Mateusz Viste
| +* Re: How to avoid an overflow during multiplication?Stefan Ram
| |+* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||`* Re: How to avoid an overflow during multiplication?Keith Thompson
| || `* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  +* Re: How to avoid an overflow during multiplication?James Kuyper
| ||  |`* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  | `* Re: How to avoid an overflow during multiplication?Tim Rentsch
| ||  |  `* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |   +* Re: How to avoid an overflow during multiplication?David Brown
| ||  |   |`* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |   | +- Re: How to avoid an overflow during multiplication?James Kuyper
| ||  |   | `* Re: How to avoid an overflow during multiplication?David Brown
| ||  |   |  `* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |   |   `* Re: How to avoid an overflow during multiplication?David Brown
| ||  |   |    `* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |   |     `* Re: How to avoid an overflow during multiplication?David Brown
| ||  |   |      `* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |   |       `* Re: How to avoid an overflow during multiplication?Richard Damon
| ||  |   |        +* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |   |        |`* Re: How to avoid an overflow during multiplication?David Brown
| ||  |   |        | `* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |   |        |  `- Re: How to avoid an overflow during multiplication?David Brown
| ||  |   |        `* Re: How to avoid an overflow during multiplication?Tim Rentsch
| ||  |   |         `* Re: How to avoid an overflow during multiplication?David Brown
| ||  |   |          `* Re: How to avoid an overflow during multiplication?Bart
| ||  |   |           `* Re: How to avoid an overflow during multiplication?Öö Tiib
| ||  |   |            +- Re: How to avoid an overflow during multiplication?Bart
| ||  |   |            `- Re: How to avoid an overflow during multiplication?Tim Rentsch
| ||  |   +* Re: How to avoid an overflow during multiplication?James Kuyper
| ||  |   |`* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |   | `- Re: How to avoid an overflow during multiplication?James Kuyper
| ||  |   +* Re: How to avoid an overflow during multiplication?Scott Lurndal
| ||  |   |`* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |   | `* Re: How to avoid an overflow during multiplication?Scott Lurndal
| ||  |   |  `* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |   |   +* Re: How to avoid an overflow during multiplication?Scott Lurndal
| ||  |   |   |`* Re: How to avoid an overflow during multiplication?Tim Rentsch
| ||  |   |   | `* Re: How to avoid an overflow during multiplication?Scott Lurndal
| ||  |   |   |  `* Re: How to avoid an overflow during multiplication?Tim Rentsch
| ||  |   |   |   `* Re: How to avoid an overflow during multiplication?Scott Lurndal
| ||  |   |   |    +* Re: How to avoid an overflow during multiplication?Scott Lurndal
| ||  |   |   |    |`* Re: How to avoid an overflow during multiplication?Tim Rentsch
| ||  |   |   |    | `* Re: How to avoid an overflow during multiplication?Scott Lurndal
| ||  |   |   |    |  +* Re: How to avoid an overflow during multiplication?Keith Thompson
| ||  |   |   |    |  |`* Re: How to avoid an overflow during multiplication?Scott Lurndal
| ||  |   |   |    |  | +* Re: How to avoid an overflow during multiplication?Ben Bacarisse
| ||  |   |   |    |  | |`- Re: How to avoid an overflow during multiplication?Scott Lurndal
| ||  |   |   |    |  | `* Re: How to avoid an overflow during multiplication?Keith Thompson
| ||  |   |   |    |  |  `- Re: How to avoid an overflow during multiplication?Scott Lurndal
| ||  |   |   |    |  `- Re: How to avoid an overflow during multiplication?Tim Rentsch
| ||  |   |   |    `* Re: How to avoid an overflow during multiplication?James Kuyper
| ||  |   |   |     `* Re: How to avoid an overflow during multiplication?Manfred
| ||  |   |   |      `* Re: How to avoid an overflow during multiplication?Scott Lurndal
| ||  |   |   |       `- Re: How to avoid an overflow during multiplication?Tim Rentsch
| ||  |   |   `- Re: How to avoid an overflow during multiplication?Ben Bacarisse
| ||  |   +* Re: How to avoid an overflow during multiplication?Tim Rentsch
| ||  |   |`* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |   | +- Re: How to avoid an overflow during multiplication?Tim Rentsch
| ||  |   | `* Re: How to avoid an overflow during multiplication?James Kuyper
| ||  |   |  `- Re: How to avoid an overflow during multiplication?Tim Rentsch
| ||  |   +- Re: How to avoid an overflow during multiplication?Tim Rentsch
| ||  |   `* Re: How to avoid an overflow during multiplication?Tim Rentsch
| ||  |    `* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |     `* Re: How to avoid an overflow during multiplication?Tim Rentsch
| ||  |      `* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |       +* Re: How to avoid an overflow during multiplication?Keith Thompson
| ||  |       |`- Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |       +* Re: How to avoid an overflow during multiplication?Vir Campestris
| ||  |       |`* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |       | +* Re: How to avoid an overflow during multiplication?James Kuyper
| ||  |       | |+* Re: How to avoid an overflow during multiplication?Öö Tiib
| ||  |       | ||`* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |       | || +- Re: How to avoid an overflow during multiplication?Öö Tiib
| ||  |       | || `* Re: How to avoid an overflow during multiplication?Tim Rentsch
| ||  |       | ||  `* Re: How to avoid an overflow during multiplication?Bart
| ||  |       | ||   +* Re: How to avoid an overflow during multiplication?Ben Bacarisse
| ||  |       | ||   |`- Re: How to avoid an overflow during multiplication?Bart
| ||  |       | ||   `- Re: How to avoid an overflow during multiplication?Tim Rentsch
| ||  |       | |`* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |       | | +* Re: How to avoid an overflow during multiplication?David Brown
| ||  |       | | |+* Re: How to avoid an overflow during multiplication?Malcolm McLean
| ||  |       | | ||`* Re: How to avoid an overflow during multiplication?David Brown
| ||  |       | | || `* Re: How to avoid an overflow during multiplication?Mateusz Viste
| ||  |       | | ||  `* Re: How to avoid an overflow during multiplication?David Brown
| ||  |       | | ||   `- Re: How to avoid an overflow during multiplication?Malcolm McLean
| ||  |       | | |`* Re: How to avoid an overflow during multiplication?Bart
| ||  |       | | | +* Re: How to avoid an overflow during multiplication?David Brown
| ||  |       | | | |`* Re: How to avoid an overflow during multiplication?Bart
| ||  |       | | | | +* Re: How to avoid an overflow during multiplication?David Brown
| ||  |       | | | | |+* Re: How to avoid an overflow during multiplication?Bart
| ||  |       | | | | ||`* Re: How to avoid an overflow during multiplication?David Brown
| ||  |       | | | | || `- Re: How to avoid an overflow during multiplication?Bart
| ||  |       | | | | |`* Re: How to avoid an overflow during multiplication?Manfred
| ||  |       | | | | | +* Re: How to avoid an overflow during multiplication?James Kuyper
| ||  |       | | | | | |`- Re: How to avoid an overflow during multiplication?Manfred
| ||  |       | | | | | `- Re: How to avoid an overflow during multiplication?David Brown
| ||  |       | | | | `* Re: How to avoid an overflow during multiplication?james...@alumni.caltech.edu
| ||  |       | | | `* Re: How to avoid an overflow during multiplication?james...@alumni.caltech.edu
| ||  |       | | `* Re: How to avoid an overflow during multiplication?James Kuyper
| ||  |       | +- Re: How to avoid an overflow during multiplication?Scott Lurndal
| ||  |       | `* Re: How to avoid an overflow during multiplication?Vir Campestris
| ||  |       +- Re: How to avoid an overflow during multiplication?James Kuyper
| ||  |       `* Re: How to avoid an overflow during multiplication?Tim Rentsch
| ||  `- Re: How to avoid an overflow during multiplication?Keith Thompson
| |`- Re: How to avoid an overflow during multiplication?Guillaume
| `* Re: How to avoid an overflow during multiplication?David Brown
+* Re: How to avoid an overflow during multiplication?Bonita Montero
+* Re: How to avoid an overflow during multiplication?Michael S
+* Re: How to avoid an overflow during multiplication?Kaz Kylheku
+* Re: How to avoid an overflow during multiplication?Tim Rentsch
`* Re: How to avoid an overflow during multiplication?Stefan Ram

Pages:12345678
Re: How to avoid an overflow during multiplication?

<ssje46$tpl$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20115&group=comp.lang.c#20115

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sun, 23 Jan 2022 12:28:06 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <ssje46$tpl$1@dont-email.me>
References: <sqmkg9$157v$1@gioia.aioe.org> <8735m954yz.fsf@bsb.me.uk>
<sqn0aq$1e8b$1@gioia.aioe.org>
<unsigned-20211231144041@ram.dialup.fu-berlin.de>
<sqn2dj$14ld$2@gioia.aioe.org> <877dbk36qu.fsf@nosuchdomain.example.com>
<sqnmsm$1ff8$1@gioia.aioe.org> <sqo47m$n9p$1@dont-email.me>
<sqq0lb$1g77$1@gioia.aioe.org> <86v8ydp57h.fsf@linuxsc.com>
<ssehod$hfk$1@gioia.aioe.org> <sseiun$cf0$1@dont-email.me>
<ssekpf$1flc$1@gioia.aioe.org> <ssepll$4a4$1@dont-email.me>
<sseq9h$p7v$1@gioia.aioe.org> <ssf2v1$baq$1@dont-email.me>
<ssf87g$19vr$3@gioia.aioe.org> <ssgrth$d2d$1@dont-email.me>
<ssguog$e4s$1@gioia.aioe.org> <IGTGJ.5622$1_.3043@fx37.iad>
<86tudvodft.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 23 Jan 2022 11:28:06 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="965f5bb839fade2803942f11d3f504aa";
logging-data="30517"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18so1KahIrQjumhFSkAK1BVb1GF2TcciNY="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:3k36AXHl6EzeJfiW0zK8KbnuPso=
In-Reply-To: <86tudvodft.fsf@linuxsc.com>
Content-Language: en-GB
 by: David Brown - Sun, 23 Jan 2022 11:28 UTC

On 22/01/2022 19:03, Tim Rentsch wrote:
> Richard Damon <Richard@Damon-Family.org> writes:
>
> [regarding various warning options and program style]
>
>> That one may not be, but there are some that are purely stylistic,
>> and different implementations enforce different styles.
>>
>> One big class is 'redundant' parentheses. Some implementations
>> consider some operations to have 'unnatural' precedence, and will
>> advise adding parentheses to make that explicit, while others will
>> warn that those parentheses aren't needed and are just redundant.
>
> Personally I would like to see a compiler option that warns
> in /all/ cases of redundant parentheses.
>

Do you think that would be much used? I can understand how some people
might find the warning interesting, but the prime purpose of warnings in
compilers is to help people spot possible errors in their code - code
that does not do what they think it does, or does not do what they
intended it to do.

There are other kinds of static checking systems that go beyond that to
purely stylistic matters - checking for spelling in identifiers, maximum
number of lines in a function, and whatever. This kind of check might
fit better at such a level. Both gcc and clang/llvm have frameworks for
extensions and checkers that would be suitable, allowing people to add
new checks in a high-level language (such as Python) without having to
go through the laborious process of changing the core compiler.

Re: How to avoid an overflow during multiplication?

<ssjf9l$5f4$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20116&group=comp.lang.c#20116

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sun, 23 Jan 2022 11:48:06 +0000
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <ssjf9l$5f4$1@dont-email.me>
References: <sqmkg9$157v$1@gioia.aioe.org> <8735m954yz.fsf@bsb.me.uk>
<sqn0aq$1e8b$1@gioia.aioe.org>
<unsigned-20211231144041@ram.dialup.fu-berlin.de>
<sqn2dj$14ld$2@gioia.aioe.org> <877dbk36qu.fsf@nosuchdomain.example.com>
<sqnmsm$1ff8$1@gioia.aioe.org> <sqo47m$n9p$1@dont-email.me>
<sqq0lb$1g77$1@gioia.aioe.org> <86v8ydp57h.fsf@linuxsc.com>
<ssehod$hfk$1@gioia.aioe.org> <sseiun$cf0$1@dont-email.me>
<ssekpf$1flc$1@gioia.aioe.org> <ssepll$4a4$1@dont-email.me>
<sseq9h$p7v$1@gioia.aioe.org> <ssf2v1$baq$1@dont-email.me>
<ssf87g$19vr$3@gioia.aioe.org> <ssgrth$d2d$1@dont-email.me>
<ssguog$e4s$1@gioia.aioe.org> <IGTGJ.5622$1_.3043@fx37.iad>
<86tudvodft.fsf@linuxsc.com> <ssje46$tpl$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 23 Jan 2022 11:48:05 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b4d82b131af990d8b54b5f3a24b7f329";
logging-data="5604"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196xcpY3i446pdgGDMmt83sJJVjFlsrA2I="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:vB7ixAoh4MNYwUhdaRoLr2DFQ8w=
In-Reply-To: <ssje46$tpl$1@dont-email.me>
 by: Bart - Sun, 23 Jan 2022 11:48 UTC

On 23/01/2022 11:28, David Brown wrote:
> On 22/01/2022 19:03, Tim Rentsch wrote:
>> Richard Damon <Richard@Damon-Family.org> writes:
>>
>> [regarding various warning options and program style]
>>
>>> That one may not be, but there are some that are purely stylistic,
>>> and different implementations enforce different styles.
>>>
>>> One big class is 'redundant' parentheses. Some implementations
>>> consider some operations to have 'unnatural' precedence, and will
>>> advise adding parentheses to make that explicit, while others will
>>> warn that those parentheses aren't needed and are just redundant.
>>
>> Personally I would like to see a compiler option that warns
>> in /all/ cases of redundant parentheses.
>>
>
> Do you think that would be much used? I can understand how some people
> might find the warning interesting, but the prime purpose of warnings in
> compilers is to help people spot possible errors in their code - code
> that does not do what they think it does, or does not do what they
> intended it to do.

Tim thinks that everyone should know all the C precedence levels,
including those for ?: operators, so should they should never never to
use parentheses for clarity or avoid ambiguity.

This sounds like something that can be used to catch people out. So
detecting:

a << (b + c)

is a sign that someone is unsure about relevant precedences of << and +;
they should instead write:

a << b + c

While this ought to be perfectly clear without parentheses:

a ? b ? c : d ? e : f : g;

Re: How to avoid an overflow during multiplication?

<1bb9bdc9-5c15-4fa7-8f6c-53d59a349ed6n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20118&group=comp.lang.c#20118

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ad4:5bac:: with SMTP id 12mr11891984qvq.125.1642955783857;
Sun, 23 Jan 2022 08:36:23 -0800 (PST)
X-Received: by 2002:ae9:e210:: with SMTP id c16mr883379qkc.597.1642955783648;
Sun, 23 Jan 2022 08:36:23 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sun, 23 Jan 2022 08:36:23 -0800 (PST)
In-Reply-To: <ssjf9l$5f4$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=94.246.251.164; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 94.246.251.164
References: <sqmkg9$157v$1@gioia.aioe.org> <8735m954yz.fsf@bsb.me.uk>
<sqn0aq$1e8b$1@gioia.aioe.org> <unsigned-20211231144041@ram.dialup.fu-berlin.de>
<sqn2dj$14ld$2@gioia.aioe.org> <877dbk36qu.fsf@nosuchdomain.example.com>
<sqnmsm$1ff8$1@gioia.aioe.org> <sqo47m$n9p$1@dont-email.me>
<sqq0lb$1g77$1@gioia.aioe.org> <86v8ydp57h.fsf@linuxsc.com>
<ssehod$hfk$1@gioia.aioe.org> <sseiun$cf0$1@dont-email.me>
<ssekpf$1flc$1@gioia.aioe.org> <ssepll$4a4$1@dont-email.me>
<sseq9h$p7v$1@gioia.aioe.org> <ssf2v1$baq$1@dont-email.me>
<ssf87g$19vr$3@gioia.aioe.org> <ssgrth$d2d$1@dont-email.me>
<ssguog$e4s$1@gioia.aioe.org> <IGTGJ.5622$1_.3043@fx37.iad>
<86tudvodft.fsf@linuxsc.com> <ssje46$tpl$1@dont-email.me> <ssjf9l$5f4$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1bb9bdc9-5c15-4fa7-8f6c-53d59a349ed6n@googlegroups.com>
Subject: Re: How to avoid an overflow during multiplication?
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Sun, 23 Jan 2022 16:36:23 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 21
 by: Öö Tiib - Sun, 23 Jan 2022 16:36 UTC

On Sunday, 23 January 2022 at 13:48:18 UTC+2, Bart wrote:

> While this ought to be perfectly clear without parentheses:
>
>
a ? b ? c : d ? e : f : g;

It looks bad to read for me. Parentheses do not help to reason there.
Writing in more usual to human logic may help:

!a ? g : b ? c : d ? e : f;

Also adding newlines to emphasize what is value and what condition
may help:

!a ? g
: b ? c
: d ? e
: f;

But parentheses would make original to look even more garbage.

Re: How to avoid an overflow during multiplication?

<ssk1a9$3oh$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20119&group=comp.lang.c#20119

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sun, 23 Jan 2022 16:55:39 +0000
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <ssk1a9$3oh$1@dont-email.me>
References: <sqmkg9$157v$1@gioia.aioe.org> <8735m954yz.fsf@bsb.me.uk>
<sqn0aq$1e8b$1@gioia.aioe.org>
<unsigned-20211231144041@ram.dialup.fu-berlin.de>
<sqn2dj$14ld$2@gioia.aioe.org> <877dbk36qu.fsf@nosuchdomain.example.com>
<sqnmsm$1ff8$1@gioia.aioe.org> <sqo47m$n9p$1@dont-email.me>
<sqq0lb$1g77$1@gioia.aioe.org> <86v8ydp57h.fsf@linuxsc.com>
<ssehod$hfk$1@gioia.aioe.org> <sseiun$cf0$1@dont-email.me>
<ssekpf$1flc$1@gioia.aioe.org> <ssepll$4a4$1@dont-email.me>
<sseq9h$p7v$1@gioia.aioe.org> <ssf2v1$baq$1@dont-email.me>
<ssf87g$19vr$3@gioia.aioe.org> <ssgrth$d2d$1@dont-email.me>
<ssguog$e4s$1@gioia.aioe.org> <IGTGJ.5622$1_.3043@fx37.iad>
<86tudvodft.fsf@linuxsc.com> <ssje46$tpl$1@dont-email.me>
<ssjf9l$5f4$1@dont-email.me>
<1bb9bdc9-5c15-4fa7-8f6c-53d59a349ed6n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 23 Jan 2022 16:55:37 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b4d82b131af990d8b54b5f3a24b7f329";
logging-data="3857"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19eCHPI/gDHMcJKGjz5vHnuWx71xWvc0e4="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:ljloW8MOy8AK4oGtCt8Mpp9gXiA=
In-Reply-To: <1bb9bdc9-5c15-4fa7-8f6c-53d59a349ed6n@googlegroups.com>
 by: Bart - Sun, 23 Jan 2022 16:55 UTC

On 23/01/2022 16:36, Öö Tiib wrote:
> On Sunday, 23 January 2022 at 13:48:18 UTC+2, Bart wrote:
>
>> While this ought to be perfectly clear without parentheses:
>>
>>
> a ? b ? c : d ? e : f : g;
>
> It looks bad to read for me. Parentheses do not help to reason there.
> Writing in more usual to human logic may help:
>
> !a ? g : b ? c : d ? e : f;
>
> Also adding newlines to emphasize what is value and what condition
> may help:
>
> !a ? g
> : b ? c
> : d ? e
> : f;
>
> But parentheses would make original to look even more garbage.
>

If pseudo-code, my example corresponds do:

if a then
if b then
c
else
if d then
e
else
f
end
end
else
g
end

(Transcribed from AST display of the C code.) That suggests the
parentheses would go here:

a ? (b ? c : (d ? e : f)) : g

You version is transformed, but presumably you had to already know what
it meant in order to do that.

A multi-line, indented layout would help, provided you were confident
that that was what it meant without the parentheses. But then you are
much better off using if-else. (Unfortunately in C if-else cannot return
a value.)

I only use such short-form constructs on one line.

Re: How to avoid an overflow during multiplication?

<86czkhom8w.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20131&group=comp.lang.c#20131

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sun, 23 Jan 2022 19:17:51 -0800
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <86czkhom8w.fsf@linuxsc.com>
References: <sqmkg9$157v$1@gioia.aioe.org> <sqn2dj$14ld$2@gioia.aioe.org> <877dbk36qu.fsf@nosuchdomain.example.com> <sqnmsm$1ff8$1@gioia.aioe.org> <sqo47m$n9p$1@dont-email.me> <sqq0lb$1g77$1@gioia.aioe.org> <86v8ydp57h.fsf@linuxsc.com> <ssehod$hfk$1@gioia.aioe.org> <sseiun$cf0$1@dont-email.me> <ssekpf$1flc$1@gioia.aioe.org> <ssepll$4a4$1@dont-email.me> <sseq9h$p7v$1@gioia.aioe.org> <ssf2v1$baq$1@dont-email.me> <ssf87g$19vr$3@gioia.aioe.org> <ssgrth$d2d$1@dont-email.me> <ssguog$e4s$1@gioia.aioe.org> <IGTGJ.5622$1_.3043@fx37.iad> <86tudvodft.fsf@linuxsc.com> <ssje46$tpl$1@dont-email.me> <ssjf9l$5f4$1@dont-email.me> <1bb9bdc9-5c15-4fa7-8f6c-53d59a349ed6n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="d742d26243a9575adb46fc0e29496190";
logging-data="742"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX193gw5qoe/uDGaEO1SLxRgRwDTYst4M9q4="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:4DW/jNGL9nj/NLmcFUHlw05npK0=
sha1:IIRSYGF6hjkHsYLWmqUdjzVYGI0=
 by: Tim Rentsch - Mon, 24 Jan 2022 03:17 UTC

Tiib <ootiib@hot.ee> writes:

> On Sunday, 23 January 2022 at 13:48:18 UTC+2, Bart wrote:

[edited to reflect what I believe is correct attribution]

>> While this ought to be perfectly clear without parentheses:
>>
>> a ? b ? c : d ? e : f : g;
>
> It looks bad to read for me. Parentheses do not help to reason
> there. Writing in more usual to human logic may help:
>
> !a ? g : b ? c : d ? e : f;
>
> Also adding newlines to emphasize what is value and what condition
> may help:
>
> !a ? g
> : b ? c
> : d ? e
> : f;
>
> But parentheses would make original to look even more garbage.

I don't disagree with your comments. For me though the high
order bit is that this is a pointless and contrived example,
and not deserving of any other reaction. Just like so many
other of Bart's postings.

Re: How to avoid an overflow during multiplication?

<sslo93$61s$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20137&group=comp.lang.c#20137

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!299gYy2nqWB43X4cCBV6zg.user.46.165.242.75.POSTED!not-for-mail
From: mate...@xyz.invalid (Mateusz Viste)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Mon, 24 Jan 2022 09:33:07 +0100
Organization: . . .
Message-ID: <sslo93$61s$1@gioia.aioe.org>
References: <sqmkg9$157v$1@gioia.aioe.org>
<8735m954yz.fsf@bsb.me.uk>
<sqn0aq$1e8b$1@gioia.aioe.org>
<unsigned-20211231144041@ram.dialup.fu-berlin.de>
<sqn2dj$14ld$2@gioia.aioe.org>
<877dbk36qu.fsf@nosuchdomain.example.com>
<sqnmsm$1ff8$1@gioia.aioe.org>
<sqo47m$n9p$1@dont-email.me>
<sqq0lb$1g77$1@gioia.aioe.org>
<86v8ydp57h.fsf@linuxsc.com>
<ssehod$hfk$1@gioia.aioe.org>
<sseiun$cf0$1@dont-email.me>
<ssekpf$1flc$1@gioia.aioe.org>
<ssepll$4a4$1@dont-email.me>
<sseq9h$p7v$1@gioia.aioe.org>
<ssf2v1$baq$1@dont-email.me>
<ssf87g$19vr$3@gioia.aioe.org>
<ssgrth$d2d$1@dont-email.me>
<ssguog$e4s$1@gioia.aioe.org>
<IGTGJ.5622$1_.3043@fx37.iad>
<ssh5pb$1sp1$1@gioia.aioe.org>
<ssh8t4$3mp$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="6204"; posting-host="299gYy2nqWB43X4cCBV6zg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
 by: Mateusz Viste - Mon, 24 Jan 2022 08:33 UTC

2022-01-22 at 16:46 +0100, David Brown wrote:
> The choice of whether or not you want a warning on extra padding on
> structs is a matter of style and the type of code you are writing.

Not really what you were saying earlier, but nice try.

> Yes, sometimes it matters if there is unexpected padding in your
> structs. Yes, sometimes it does /not/ matter. Neither situation
> /requires/ the warning, and neither requires that the warning is
> disabled.

In this line of thought I propose to simplify the argument to
"no warnings are required at all" and let's be done with it.

Mateusz

Re: How to avoid an overflow during multiplication?

<sslpp3$61s$2@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20138&group=comp.lang.c#20138

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!299gYy2nqWB43X4cCBV6zg.user.46.165.242.75.POSTED!not-for-mail
From: mate...@xyz.invalid (Mateusz Viste)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Mon, 24 Jan 2022 09:59:15 +0100
Organization: . . .
Message-ID: <sslpp3$61s$2@gioia.aioe.org>
References: <sqmkg9$157v$1@gioia.aioe.org>
<8735m954yz.fsf@bsb.me.uk>
<sqn0aq$1e8b$1@gioia.aioe.org>
<unsigned-20211231144041@ram.dialup.fu-berlin.de>
<sqn2dj$14ld$2@gioia.aioe.org>
<877dbk36qu.fsf@nosuchdomain.example.com>
<sqnmsm$1ff8$1@gioia.aioe.org>
<sqo47m$n9p$1@dont-email.me>
<sqq0lb$1g77$1@gioia.aioe.org>
<86v8ydp57h.fsf@linuxsc.com>
<ssehod$hfk$1@gioia.aioe.org>
<86pmojo7th.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="6204"; posting-host="299gYy2nqWB43X4cCBV6zg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
 by: Mateusz Viste - Mon, 24 Jan 2022 08:59 UTC

2022-01-22 at 12:04 -0800, Tim Rentsch wrote:
> To be explicit the above is not meant as an argument to convince
> you. I am however interested in whatever reactions you might
> have.

My reaction is simply that in real world, there's no one ring to rule
them all. Each of us has to choose the tools that suit him best, based
on many things: the exact need at hand, personal preferences, and
personal limitations to name only the few that come to mind immediately.

> I have looked through the list of changes between C90 and C99 and
> don't see anything else that looks objectionable. Can I ask you
> to provide a more comprehensive list? I really am at a loss to
> know what sorts of things you wouldn't like and also would be
> tempted to use.

It's not only about temptation, it also about using tools that are as
simple as possible. I like games with simple rules - one reason why I
prefer Go over chess. Some say it's because I lack brain power, and
they may be right. Now, C99 isn't *that* much of a complication that I
couldn't grasp it, but then where do I draw the line? C89 (or its gnu
dialect) works for me and allows me to do the jobs I need to do without
pain, so why bother.

Now, about features that I don't like in C99:
- VLAs (temptation argument again, that may lead to stack exhaustion)
- bool (don't see what added value this brings)
- complex & imaginary numbers (I admit those may be useful in some
niche usage, but *I* never had such need)

I also agree that C99 brings its share of improvements, which are part
of the set of features I had listed earlier. But so does the gnu89
dialect, with the extra layer of POSIX that I often rely on. Hence in
my very personal usage I consider gnu89 to be a pretty optimal tool.
And I do not expect other people to agree, because of the reasons
stated earlier.

Mateusz

Re: How to avoid an overflow during multiplication?

<sslqnv$9v2$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20139&group=comp.lang.c#20139

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Mon, 24 Jan 2022 10:15:43 +0100
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <sslqnv$9v2$1@dont-email.me>
References: <sqmkg9$157v$1@gioia.aioe.org> <8735m954yz.fsf@bsb.me.uk>
<sqn0aq$1e8b$1@gioia.aioe.org>
<unsigned-20211231144041@ram.dialup.fu-berlin.de>
<sqn2dj$14ld$2@gioia.aioe.org> <877dbk36qu.fsf@nosuchdomain.example.com>
<sqnmsm$1ff8$1@gioia.aioe.org> <sqo47m$n9p$1@dont-email.me>
<sqq0lb$1g77$1@gioia.aioe.org> <86v8ydp57h.fsf@linuxsc.com>
<ssehod$hfk$1@gioia.aioe.org> <sseiun$cf0$1@dont-email.me>
<ssekpf$1flc$1@gioia.aioe.org> <ssepll$4a4$1@dont-email.me>
<sseq9h$p7v$1@gioia.aioe.org> <ssf2v1$baq$1@dont-email.me>
<ssf87g$19vr$3@gioia.aioe.org> <ssgrth$d2d$1@dont-email.me>
<ssguog$e4s$1@gioia.aioe.org> <IGTGJ.5622$1_.3043@fx37.iad>
<ssh5pb$1sp1$1@gioia.aioe.org> <ssh8t4$3mp$1@dont-email.me>
<sslo93$61s$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jan 2022 09:15:43 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="fc65e1acc1fd2348a3e7a6c821961c75";
logging-data="10210"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ijO/OknFyrOiVMS8dMMJBGHzh/PJjuuE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:Zqjt+nry89nlb79z1YnMcY3ORh4=
In-Reply-To: <sslo93$61s$1@gioia.aioe.org>
Content-Language: en-GB
 by: David Brown - Mon, 24 Jan 2022 09:15 UTC

On 24/01/2022 09:33, Mateusz Viste wrote:
> 2022-01-22 at 16:46 +0100, David Brown wrote:
>> The choice of whether or not you want a warning on extra padding on
>> structs is a matter of style and the type of code you are writing.
>
> Not really what you were saying earlier, but nice try.
>
>> Yes, sometimes it matters if there is unexpected padding in your
>> structs. Yes, sometimes it does /not/ matter. Neither situation
>> /requires/ the warning, and neither requires that the warning is
>> disabled.
>
> In this line of thought I propose to simplify the argument to
> "no warnings are required at all" and let's be done with it.
>

I'm not sure why you have decided this is some sort of battle rather
than sharing experiences and suggestions for how to get the most help
from your compiler, but I guess we are done with this thread.

Re: How to avoid an overflow during multiplication?

<86v8y9m8ba.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20148&group=comp.lang.c#20148

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Mon, 24 Jan 2022 08:01:45 -0800
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <86v8y9m8ba.fsf@linuxsc.com>
References: <sqmkg9$157v$1@gioia.aioe.org> <sqn2dj$14ld$2@gioia.aioe.org> <877dbk36qu.fsf@nosuchdomain.example.com> <sqnmsm$1ff8$1@gioia.aioe.org> <sqo47m$n9p$1@dont-email.me> <sqq0lb$1g77$1@gioia.aioe.org> <86v8ydp57h.fsf@linuxsc.com> <ssehod$hfk$1@gioia.aioe.org> <9_BGJ.170561$X2_b.72894@fx09.ams4> <sseqsk$19vr$1@gioia.aioe.org> <pCCGJ.338776$6kH7.305209@fx03.ams4> <ssf045$19vr$2@gioia.aioe.org> <CCDGJ.246968$Gbad.173877@fx12.ams4> <86mtjopoq5.fsf@linuxsc.com> <RJWGJ.370432$tX27.294028@fx04.ams4>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="d742d26243a9575adb46fc0e29496190";
logging-data="3706"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/LeLRGQbxlG8PhcFJ2LDDjxugZgF8jX44="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:piExMmGx03sHKRvkGzVDNVAbxx8=
sha1:Mj5bpAOsPjnCxsSsAy2du1ft8/4=
 by: Tim Rentsch - Mon, 24 Jan 2022 16:01 UTC

scott@slp53.sl.home (Scott Lurndal) writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> scott@slp53.sl.home (Scott Lurndal) writes:
>>
>>> [...] I've seen some pretty long functions that are not easily
>>> amenable to factorization into smaller functions for structural
>>> or performance reasons.
>>
>> Can you post an example or two of those? Ideally one of each, one
>> where structure impedes refactoring and one where performance
>> impedes refactoring.
>
> Probably not without violating various non-disclosure or employment
> agreements.

Surely you can find some example that wouldn't go against your
existing agreements. Probably even one of the covered examples
would be okay if stripped of comments and had all the identifers
changed to randomly chosen names (and for good measure take out
all extra horizontal white space). The code doesn't have to
compile, just show the "shape" of the function; it's unlikely
that would be giving away any kind of trade secrets. And it
doesn't have to be one of the very longest functions; in fact
between 50 and 100 lines is probably easier than some super long
monster. (Having said that, I wouldn't mind a much longer
function if that's the best you can find.)

> One in particular is the code to handle page table walks in
> an ARM64 processor simulator. Another was handling the fork()
> system call in a unix-derived MPP operating system. Both in C++.

This is comp.lang.c. My question is about C code, not C++ code.
C++ is a completely different animal.

Re: How to avoid an overflow during multiplication?

<HoAHJ.12386$1_.5423@fx37.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20149&group=comp.lang.c#20149

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx37.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: How to avoid an overflow during multiplication?
Newsgroups: comp.lang.c
References: <sqmkg9$157v$1@gioia.aioe.org> <877dbk36qu.fsf@nosuchdomain.example.com> <sqnmsm$1ff8$1@gioia.aioe.org> <sqo47m$n9p$1@dont-email.me> <sqq0lb$1g77$1@gioia.aioe.org> <86v8ydp57h.fsf@linuxsc.com> <ssehod$hfk$1@gioia.aioe.org> <9_BGJ.170561$X2_b.72894@fx09.ams4> <sseqsk$19vr$1@gioia.aioe.org> <pCCGJ.338776$6kH7.305209@fx03.ams4> <ssf045$19vr$2@gioia.aioe.org> <CCDGJ.246968$Gbad.173877@fx12.ams4> <86mtjopoq5.fsf@linuxsc.com> <RJWGJ.370432$tX27.294028@fx04.ams4> <86v8y9m8ba.fsf@linuxsc.com>
Lines: 46
Message-ID: <HoAHJ.12386$1_.5423@fx37.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Mon, 24 Jan 2022 16:24:07 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 24 Jan 2022 16:24:07 GMT
X-Received-Bytes: 3003
X-Original-Bytes: 2952
 by: Scott Lurndal - Mon, 24 Jan 2022 16:24 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>scott@slp53.sl.home (Scott Lurndal) writes:
>
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>
>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>
>>>> [...] I've seen some pretty long functions that are not easily
>>>> amenable to factorization into smaller functions for structural
>>>> or performance reasons.
>>>
>>> Can you post an example or two of those? Ideally one of each, one
>>> where structure impedes refactoring and one where performance
>>> impedes refactoring.
>>
>> Probably not without violating various non-disclosure or employment
>> agreements.
>
>Surely you can find some example that wouldn't go against your
>existing agreements. Probably even one of the covered examples
>would be okay if stripped of comments and had all the identifers
>changed to randomly chosen names (and for good measure take out
>all extra horizontal white space). The code doesn't have to
>compile, just show the "shape" of the function; it's unlikely
>that would be giving away any kind of trade secrets. And it
>doesn't have to be one of the very longest functions; in fact
>between 50 and 100 lines is probably easier than some super long
>monster. (Having said that, I wouldn't mind a much longer
>function if that's the best you can find.)

I do tend to honor copyrights, which precludes much of this.

>
>> One in particular is the code to handle page table walks in
>> an ARM64 processor simulator. Another was handling the fork()
>> system call in a unix-derived MPP operating system. Both in C++.
>
>This is comp.lang.c. My question is about C code, not C++ code.
>C++ is a completely different animal.

No, it's just C with added capabilities.

And if I ever get some free time where I have nothing else to do,
and your request bubbles up to the top of the future-to-do list,
I'll spend the time to find an example and clear it for public
display.

Re: How to avoid an overflow during multiplication?

<tuBHJ.15393$jb4.14798@fx24.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20151&group=comp.lang.c#20151

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx24.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: How to avoid an overflow during multiplication?
Newsgroups: comp.lang.c
References: <sqmkg9$157v$1@gioia.aioe.org> <sqnmsm$1ff8$1@gioia.aioe.org> <sqo47m$n9p$1@dont-email.me> <sqq0lb$1g77$1@gioia.aioe.org> <86v8ydp57h.fsf@linuxsc.com> <ssehod$hfk$1@gioia.aioe.org> <9_BGJ.170561$X2_b.72894@fx09.ams4> <sseqsk$19vr$1@gioia.aioe.org> <pCCGJ.338776$6kH7.305209@fx03.ams4> <ssf045$19vr$2@gioia.aioe.org> <CCDGJ.246968$Gbad.173877@fx12.ams4> <86mtjopoq5.fsf@linuxsc.com> <RJWGJ.370432$tX27.294028@fx04.ams4> <86v8y9m8ba.fsf@linuxsc.com> <HoAHJ.12386$1_.5423@fx37.iad>
Lines: 344
Message-ID: <tuBHJ.15393$jb4.14798@fx24.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Mon, 24 Jan 2022 17:38:33 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 24 Jan 2022 17:38:33 GMT
X-Received-Bytes: 8473
X-Original-Bytes: 8422
 by: Scott Lurndal - Mon, 24 Jan 2022 17:38 UTC

scott@slp53.sl.home (Scott Lurndal) writes:
>Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>scott@slp53.sl.home (Scott Lurndal) writes:

>>Surely you can find some example that wouldn't go against your
>>existing agreements.

Ok, a long C function:

/**
* Scaled down version of printf(3).
*
* Two additional formats:
*
* The format %b is supported to decode error registers.
* Its usage is:
*
* <tt>
* printf("reg=%b\n", regval, "\<base\>\<arg\>*");
* </tt>
*
* where \<base\> is the output base expressed as a control character, e.g.
* \\10 gives octal; \\20 gives hex. Each arg is a sequence of characters,
* the first of which gives the bit number to be inspected (origin 1), and
* the next characters (up to a control character, i.e. a character &lt;= 32),
* give the name of the register. Thus:
*
* <tt><pre>
* printf("reg=%b\n", 3, "\10\2BITTWO\1BITONE\n");
* </pre></tt>
*
* would produce output:
*
* <tt>
* reg=3&lt;BITTWO,BITONE&gt;
* </tt>
*
* XXX: %D -- Hexdump, takes pointer and separator string:
* ("%6D", ptr, ":") -&gt; XX:XX:XX:XX:XX:XX
* ("%*D", len, ptr, " " -&gt; XX XX XX XX ...
*
* @param fmt pointer to printf format string
* @param ap pointer to argument list
* @param buf pointer to buffer to receive formatted, zero terminated results
* @param limit number of chars buf can hold, INCLUDING zero termination
* @return the number of chars put into buf, does NOT include zero terminator
*/
size_t
format(const char *fmt, va_list ap, char *buf, size_t limit)
{

/* Reserve one byte for '\0', in buffer overflow case. */
#define PCHAR(c) {int cc=(c); if (retval < (limit - 1)) {*d++ = cc; retval++;} }

char nbuf[MAXNBUF];
char *d = buf;
const char *p, *percent, *q;
uint8 *up;
int ch, n;
uint64 num;
int base, lflag, qflag, tmp, width, ladjust, sharpflag, neg, sign, dot;
int cflag, hflag, jflag, tflag, zflag;
int dwidth;
char padc;
size_t retval = 0;

num = 0;

if (fmt == NULL)
fmt = "(fmt null)\n";

for (;;) {
padc = ' ';
width = 0;
while ((ch = (uint8)*fmt++) != '%') {
if (ch == '\0') {
*d++ = '\0';
retval++;
return (retval);
}
PCHAR(ch);
}
percent = fmt - 1;
qflag = 0; lflag = 0; ladjust = 0; sharpflag = 0; neg = 0;
sign = 0; dot = 0; dwidth = 0;
cflag = 0; hflag = 0; jflag = 0; tflag = 0; zflag = 0;
reswitch: switch (ch = (uint8)*fmt++) {
case '.':
dot = 1;
goto reswitch;
case '#':
sharpflag = 1;
goto reswitch;
case '+':
sign = 1;
goto reswitch;
case '-':
ladjust = 1;
goto reswitch;
case '%':
PCHAR(ch);
break;
case '*':
if (!dot) {
width = va_arg(ap, int);
if (width < 0) {
ladjust = !ladjust;
width = -width;
}
} else {
dwidth = va_arg(ap, int);
}
goto reswitch;
case '0':
if (!dot) {
padc = '0';
goto reswitch;
}
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
for (n = 0;; ++fmt) {
n = n * 10 + ch - '0';
ch = *fmt;
if (ch < '0' || ch > '9')
break;
}
if (dot)
dwidth = n;
else
width = n;
goto reswitch;
case 'b':
num = (uint32)va_arg(ap, int);
p = va_arg(ap, char *);
for (q = ksprintn(nbuf, num, *p++, NULL); *q;)
PCHAR(*q--);

if (num == 0)
break;

for (tmp = 0; *p;) {
n = *p++;
if (num & (1 << (n - 1))) {
PCHAR(tmp ? ',' : '<');
for (; (n = *p) > ' '; ++p)
PCHAR(n);
tmp = 1;
} else
for (; *p > ' '; ++p)
continue;
}
if (tmp)
PCHAR('>');
break;
case 'c':
PCHAR(va_arg(ap, int));
break;
case 'D':
up = va_arg(ap, uint8 *);
p = va_arg(ap, char *);
if (!width)
width = 16;
while(width--) {
PCHAR(hex2ascii(*up >> 4));
PCHAR(hex2ascii(*up & 0x0f));
up++;
if (width)
for (q=p;*q;q++)
PCHAR(*q);
}
break;
case 'd':
case 'i':
base = 10;
sign = 1;
goto handle_sign;
case 'h':
if (hflag) {
hflag = 0;
cflag = 1;
} else
hflag = 1;
goto reswitch;
case 'j':
jflag = 1;
goto reswitch;
case 'l':
if (lflag) {
lflag = 0;
qflag = 1;
} else
lflag = 1;
goto reswitch;
case 'n':
if (jflag)
*(va_arg(ap, int64 *)) = retval;
else if (qflag)
*(va_arg(ap, int64 *)) = retval;
else if (lflag)
*(va_arg(ap, long *)) = retval;
else if (zflag)
*(va_arg(ap, size_t *)) = retval;
else if (hflag)
*(va_arg(ap, short *)) = retval;
else if (cflag)
*(va_arg(ap, char *)) = retval;
else
*(va_arg(ap, int *)) = retval;
break;
case 'o':
base = 8;
goto handle_nosign;
case 'p':
base = 16;
sharpflag = (width == 0);
sign = 0;
num = (uintptr_t)va_arg(ap, void *);
goto number;
case 'q':
qflag = 1;
goto reswitch;
case 's':
p = va_arg(ap, char *);
if (p == NULL)
p = "(null)";
if (!dot)
n = strlen (p);
else
for (n = 0; n < dwidth && p[n]; n++)
continue;

width -= n;

if (!ladjust && width > 0)
while (width--)
PCHAR(padc);
while (n--)
PCHAR(*p++);
if (ladjust && width > 0)
while (width--)
PCHAR(padc);
break;
case 't':
tflag = 1;
goto reswitch;
case 'u':
base = 10;
goto handle_nosign;
case 'x':
case 'X':
if (dot) {
padc = '0';
}
base = 16;
goto handle_nosign;
case 'y':
base = 16;
sign = 1;
goto handle_sign;
case 'z':
zflag = 1;
goto reswitch;
handle_nosign:
sign = 0;
if (jflag)
num = va_arg(ap, uint64);
else if (qflag)
num = va_arg(ap, uint64);
else if (tflag)
num = va_arg(ap, int64);
else if (lflag)
num = va_arg(ap, uint64);
else if (zflag)
num = va_arg(ap, size_t);
else if (hflag)
num = (uint16)va_arg(ap, int);
else if (cflag)
num = (uint8)va_arg(ap, int);
else
num = va_arg(ap, uint32);
goto number;
handle_sign:
if (jflag)
num = va_arg(ap, int64);
else if (qflag)
num = va_arg(ap, int64);
else if (tflag)
num = va_arg(ap, int64);
else if (lflag)
num = va_arg(ap, long);
else if (zflag)
num = va_arg(ap, size_t);
else if (hflag)
num = (short)va_arg(ap, int);
else if (cflag)
num = (char)va_arg(ap, int);
else
num = va_arg(ap, int);
number:
if (sign && (int64)num < 0) {
neg = 1;
num = -(int64)num;
}
p = ksprintn(nbuf, num, base, &tmp);
if (sharpflag && num != 0) {
if (base == 8)
tmp++;
else if (base == 16)
tmp += 2;
}
if (neg)
tmp++;

if (!ladjust && width && (width -= tmp) > 0)
while (width--)
PCHAR(padc);
if (neg)
PCHAR('-');
if (sharpflag && num != 0) {
if (base == 8) {
PCHAR('0');
} else if (base == 16) {
PCHAR('0');
PCHAR('x');
}
}

while (*p)
PCHAR(*p--);

if (ladjust && width && (width -= tmp) > 0)
while (width--)
PCHAR(padc);

break;
default:
while (percent < fmt)
PCHAR(*percent++);
break;
}
}
#undef PCHAR
}

Re: How to avoid an overflow during multiplication?

<86r18xlyqk.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20156&group=comp.lang.c#20156

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Mon, 24 Jan 2022 11:28:35 -0800
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <86r18xlyqk.fsf@linuxsc.com>
References: <sqmkg9$157v$1@gioia.aioe.org> <sqnmsm$1ff8$1@gioia.aioe.org> <sqo47m$n9p$1@dont-email.me> <sqq0lb$1g77$1@gioia.aioe.org> <86v8ydp57h.fsf@linuxsc.com> <ssehod$hfk$1@gioia.aioe.org> <9_BGJ.170561$X2_b.72894@fx09.ams4> <sseqsk$19vr$1@gioia.aioe.org> <pCCGJ.338776$6kH7.305209@fx03.ams4> <ssf045$19vr$2@gioia.aioe.org> <CCDGJ.246968$Gbad.173877@fx12.ams4> <86mtjopoq5.fsf@linuxsc.com> <RJWGJ.370432$tX27.294028@fx04.ams4> <86v8y9m8ba.fsf@linuxsc.com> <HoAHJ.12386$1_.5423@fx37.iad> <tuBHJ.15393$jb4.14798@fx24.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="d742d26243a9575adb46fc0e29496190";
logging-data="13974"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18K5XfkQgGArpzQCjL65Swb8PkCnMoK3C8="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:+e+05VPZ9Nbkre8P+LydWA1JXp0=
sha1:SLYH/8srONvANCeEAqeMkjchCrY=
 by: Tim Rentsch - Mon, 24 Jan 2022 19:28 UTC

scott@slp53.sl.home (Scott Lurndal) writes:

> scott@slp53.sl.home (Scott Lurndal) writes:
>
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>
>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>
>>> Surely you can find some example that wouldn't go against your
>>> existing agreements.
>
> Ok, a long C function: [...]

Good, thank you for tracking down what looks like a good
example.

Before I look any further, are there any particular aspects
you would say are important to pay attention to or that
contribute to difficulty in refactoring?

Re: How to avoid an overflow during multiplication?

<_YFHJ.874$dV.864@fx44.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20162&group=comp.lang.c#20162

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx44.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: How to avoid an overflow during multiplication?
Newsgroups: comp.lang.c
References: <sqmkg9$157v$1@gioia.aioe.org> <sqq0lb$1g77$1@gioia.aioe.org> <86v8ydp57h.fsf@linuxsc.com> <ssehod$hfk$1@gioia.aioe.org> <9_BGJ.170561$X2_b.72894@fx09.ams4> <sseqsk$19vr$1@gioia.aioe.org> <pCCGJ.338776$6kH7.305209@fx03.ams4> <ssf045$19vr$2@gioia.aioe.org> <CCDGJ.246968$Gbad.173877@fx12.ams4> <86mtjopoq5.fsf@linuxsc.com> <RJWGJ.370432$tX27.294028@fx04.ams4> <86v8y9m8ba.fsf@linuxsc.com> <HoAHJ.12386$1_.5423@fx37.iad> <tuBHJ.15393$jb4.14798@fx24.iad> <86r18xlyqk.fsf@linuxsc.com>
Lines: 64
Message-ID: <_YFHJ.874$dV.864@fx44.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Mon, 24 Jan 2022 22:44:10 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 24 Jan 2022 22:44:10 GMT
X-Received-Bytes: 3054
X-Original-Bytes: 3003
 by: Scott Lurndal - Mon, 24 Jan 2022 22:44 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>scott@slp53.sl.home (Scott Lurndal) writes:
>
>> scott@slp53.sl.home (Scott Lurndal) writes:
>>
>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>
>>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>>
>>>> Surely you can find some example that wouldn't go against your
>>>> existing agreements.
>>
>> Ok, a long C function: [...]
>
>Good, thank you for tracking down what looks like a good
>example.
>
>Before I look any further, are there any particular aspects
>you would say are important to pay attention to or that
>contribute to difficulty in refactoring?

Not really, other than that I believe this was derived
from BSD at one point.

Here's the helpers:

#define NBBY 8 /* number of bits in a byte */

/* Max number conversion buffer length: a uint64 in base 2, plus zero byte. */
#define MAXNBUF (sizeof(int64) * NBBY + 1)

char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz";

#define hex2ascii(hex) (hex2ascii_data[hex])

/**
* Put a NUL-terminated ASCII number (base <= 36) in a buffer in reverse
* order; return an optional length and a pointer to the last character
* written in the buffer (i.e., the first character of the string).
* The buffer pointed to by `nbuf' must have length >= MAXNBUF.
*
* @param nbuf buffer to hold the converted number.
* @param num The value to be converted.
* @param base The radix to be used in converting.
* @param lenp A pointer to where return the pointer to the last character
* written in the buffer. Specify NULL to not have this
* pointer returned.
* @returns A pointer to the start of the output buffer.
*/
static char *
ksprintn(char *nbuf, uint64 num, int base, int *lenp)
{ char *p;

p = nbuf;
*p = '\0';
do {
*++p = hex2ascii(num % base);
} while (num /= base);
if (lenp)
*lenp = p - nbuf;
return (p);
}

Re: How to avoid an overflow during multiplication?

<87r18wn1wd.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20165&group=comp.lang.c#20165

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Mon, 24 Jan 2022 15:34:58 -0800
Organization: None to speak of
Lines: 37
Message-ID: <87r18wn1wd.fsf@nosuchdomain.example.com>
References: <sqmkg9$157v$1@gioia.aioe.org> <sqq0lb$1g77$1@gioia.aioe.org>
<86v8ydp57h.fsf@linuxsc.com> <ssehod$hfk$1@gioia.aioe.org>
<9_BGJ.170561$X2_b.72894@fx09.ams4> <sseqsk$19vr$1@gioia.aioe.org>
<pCCGJ.338776$6kH7.305209@fx03.ams4> <ssf045$19vr$2@gioia.aioe.org>
<CCDGJ.246968$Gbad.173877@fx12.ams4> <86mtjopoq5.fsf@linuxsc.com>
<RJWGJ.370432$tX27.294028@fx04.ams4> <86v8y9m8ba.fsf@linuxsc.com>
<HoAHJ.12386$1_.5423@fx37.iad> <tuBHJ.15393$jb4.14798@fx24.iad>
<86r18xlyqk.fsf@linuxsc.com> <_YFHJ.874$dV.864@fx44.iad>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="fbd031f938b902ca86c8b061f35a7f8c";
logging-data="4408"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18diABQ7mnaHbepPW4o8fbR"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:sG6ucnj9zCFjt4DvME1HKj1Tp5I=
sha1:tV6k+YUGC7TAvMouJHDG53ZN5tE=
 by: Keith Thompson - Mon, 24 Jan 2022 23:34 UTC

scott@slp53.sl.home (Scott Lurndal) writes:
> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>scott@slp53.sl.home (Scott Lurndal) writes:
>>
>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>
>>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>>
>>>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>>>
>>>>> Surely you can find some example that wouldn't go against your
>>>>> existing agreements.
>>>
>>> Ok, a long C function: [...]
>>
>>Good, thank you for tracking down what looks like a good
>>example.
>>
>>Before I look any further, are there any particular aspects
>>you would say are important to pay attention to or that
>>contribute to difficulty in refactoring?
>
> Not really, other than that I believe this was derived
> from BSD at one point.
>
> Here's the helpers:
>
> #define NBBY 8 /* number of bits in a byte */

Why not just use CHAR_BIT?

[...]

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: How to avoid an overflow during multiplication?

<713da016-3175-4d0b-79b6-698d675c2e04@alumni.caltech.edu>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20167&group=comp.lang.c#20167

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Mon, 24 Jan 2022 21:50:58 -0500
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <713da016-3175-4d0b-79b6-698d675c2e04@alumni.caltech.edu>
References: <sqmkg9$157v$1@gioia.aioe.org>
<877dbk36qu.fsf@nosuchdomain.example.com> <sqnmsm$1ff8$1@gioia.aioe.org>
<sqo47m$n9p$1@dont-email.me> <sqq0lb$1g77$1@gioia.aioe.org>
<86v8ydp57h.fsf@linuxsc.com> <ssehod$hfk$1@gioia.aioe.org>
<9_BGJ.170561$X2_b.72894@fx09.ams4> <sseqsk$19vr$1@gioia.aioe.org>
<pCCGJ.338776$6kH7.305209@fx03.ams4> <ssf045$19vr$2@gioia.aioe.org>
<CCDGJ.246968$Gbad.173877@fx12.ams4> <86mtjopoq5.fsf@linuxsc.com>
<RJWGJ.370432$tX27.294028@fx04.ams4> <86v8y9m8ba.fsf@linuxsc.com>
<HoAHJ.12386$1_.5423@fx37.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="a59f3848dc39cbe415e127036020ed39";
logging-data="676"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+L05IblWRG5fBFFl0Ka813f5KSxPJO4Aw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:59smoJY0qzXa9jHaYmjtZzp0ARo=
In-Reply-To: <HoAHJ.12386$1_.5423@fx37.iad>
Content-Language: en-US
 by: James Kuyper - Tue, 25 Jan 2022 02:50 UTC

On 1/24/22 11:24, Scott Lurndal wrote:
> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
....
>> This is comp.lang.c. My question is about C code, not C++ code.
>> C++ is a completely different animal.

That's false, but so is the following:

> No, it's just C with added capabilities.

The C++ standard devotes 8 pages (C.5) to describing differences between
the way C and C++ handle a variety of issues, and another pair of pages
(C.6) that describe how the version of the C standard library that is
supported as part of the C++ standard library differs from the one
described by the C standard. That's not a lot out of a standard that
runs 1826 pages, but it not entirely negligible, either.

Note that those lists do not include the features that C++ has that C
doesn't - they're about differences in the way that features shared
between the two languages work.

Re: How to avoid an overflow during multiplication?

<L6UHJ.15869$mS1.11374@fx10.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20180&group=comp.lang.c#20180

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx10.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: How to avoid an overflow during multiplication?
Newsgroups: comp.lang.c
References: <sqmkg9$157v$1@gioia.aioe.org> <ssehod$hfk$1@gioia.aioe.org> <9_BGJ.170561$X2_b.72894@fx09.ams4> <sseqsk$19vr$1@gioia.aioe.org> <pCCGJ.338776$6kH7.305209@fx03.ams4> <ssf045$19vr$2@gioia.aioe.org> <CCDGJ.246968$Gbad.173877@fx12.ams4> <86mtjopoq5.fsf@linuxsc.com> <RJWGJ.370432$tX27.294028@fx04.ams4> <86v8y9m8ba.fsf@linuxsc.com> <HoAHJ.12386$1_.5423@fx37.iad> <tuBHJ.15393$jb4.14798@fx24.iad> <86r18xlyqk.fsf@linuxsc.com> <_YFHJ.874$dV.864@fx44.iad> <87r18wn1wd.fsf@nosuchdomain.example.com>
Lines: 34
Message-ID: <L6UHJ.15869$mS1.11374@fx10.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Tue, 25 Jan 2022 14:50:19 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Tue, 25 Jan 2022 14:50:19 GMT
X-Received-Bytes: 2172
 by: Scott Lurndal - Tue, 25 Jan 2022 14:50 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>scott@slp53.sl.home (Scott Lurndal) writes:
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>scott@slp53.sl.home (Scott Lurndal) writes:
>>>
>>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>>
>>>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>>>
>>>>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>>>>
>>>>>> Surely you can find some example that wouldn't go against your
>>>>>> existing agreements.
>>>>
>>>> Ok, a long C function: [...]
>>>
>>>Good, thank you for tracking down what looks like a good
>>>example.
>>>
>>>Before I look any further, are there any particular aspects
>>>you would say are important to pay attention to or that
>>>contribute to difficulty in refactoring?
>>
>> Not really, other than that I believe this was derived
>> from BSD at one point.
^^^
>>
>> Here's the helpers:
>>
>> #define NBBY 8 /* number of bits in a byte */
>
>Why not just use CHAR_BIT?

Was CHAR_BIT available in 1983?

Re: How to avoid an overflow during multiplication?

<sspf9d$1877$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20186&group=comp.lang.c#20186

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!Puiiztk9lHEEQC0y3uUjRA.user.46.165.242.75.POSTED!not-for-mail
From: inva...@invalid.add (Manfred)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Tue, 25 Jan 2022 19:24:44 +0100
Organization: Aioe.org NNTP Server
Message-ID: <sspf9d$1877$1@gioia.aioe.org>
References: <sqmkg9$157v$1@gioia.aioe.org>
<877dbk36qu.fsf@nosuchdomain.example.com> <sqnmsm$1ff8$1@gioia.aioe.org>
<sqo47m$n9p$1@dont-email.me> <sqq0lb$1g77$1@gioia.aioe.org>
<86v8ydp57h.fsf@linuxsc.com> <ssehod$hfk$1@gioia.aioe.org>
<9_BGJ.170561$X2_b.72894@fx09.ams4> <sseqsk$19vr$1@gioia.aioe.org>
<pCCGJ.338776$6kH7.305209@fx03.ams4> <ssf045$19vr$2@gioia.aioe.org>
<CCDGJ.246968$Gbad.173877@fx12.ams4> <86mtjopoq5.fsf@linuxsc.com>
<RJWGJ.370432$tX27.294028@fx04.ams4> <86v8y9m8ba.fsf@linuxsc.com>
<HoAHJ.12386$1_.5423@fx37.iad>
<713da016-3175-4d0b-79b6-698d675c2e04@alumni.caltech.edu>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="41191"; posting-host="Puiiztk9lHEEQC0y3uUjRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:52.0) Gecko/20100101
Thunderbird/52.9.1
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Manfred - Tue, 25 Jan 2022 18:24 UTC

On 1/25/2022 3:50 AM, James Kuyper wrote:
> On 1/24/22 11:24, Scott Lurndal wrote:
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> ...
>>> This is comp.lang.c. My question is about C code, not C++ code.
>>> C++ is a completely different animal.
>
> That's false, but so is the following:
>
>> No, it's just C with added capabilities.
>
> The C++ standard devotes 8 pages (C.5) to describing differences between
> the way C and C++ handle a variety of issues, and another pair of pages
> (C.6) that describe how the version of the C standard library that is
> supported as part of the C++ standard library differs from the one
> described by the C standard. That's not a lot out of a standard that
> runs 1826 pages, but it not entirely negligible, either.
>
> Note that those lists do not include the features that C++ has that C
> doesn't - they're about differences in the way that features shared
> between the two languages work.
>

All true; it may also be worth recalling that this subthread is about
justification of long functions, and that C++ was brought up in this
comment:

> ... In most cases, they were in bare-metal performance
> critical code (operating systems, hypervisors) in C and C++.
>
> One in particular is the code to handle page table walks in
> an ARM64 processor simulator. Another was handling the fork()
> system call in a unix-derived MPP operating system. Both in C++.

Now, it is one of the goals of C++ compared to C to be able to write
more efficient and thus more compact code. I don't think C++ has failed
in this respect - the criticism of those who favor C against C++ may be
about complexity of the language, or lack of expressiveness in terms of
clarity, but not being more verbose than C.

In particular, with reference to the example posted elsethread,
replacing long 'switch' blocks with more structured constructs is one
typical refactoring when porting to C++.

Re: How to avoid an overflow during multiplication?

<87lez31xcs.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20187&group=comp.lang.c#20187

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Tue, 25 Jan 2022 18:30:59 +0000
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <87lez31xcs.fsf@bsb.me.uk>
References: <sqmkg9$157v$1@gioia.aioe.org> <ssehod$hfk$1@gioia.aioe.org>
<9_BGJ.170561$X2_b.72894@fx09.ams4> <sseqsk$19vr$1@gioia.aioe.org>
<pCCGJ.338776$6kH7.305209@fx03.ams4> <ssf045$19vr$2@gioia.aioe.org>
<CCDGJ.246968$Gbad.173877@fx12.ams4> <86mtjopoq5.fsf@linuxsc.com>
<RJWGJ.370432$tX27.294028@fx04.ams4> <86v8y9m8ba.fsf@linuxsc.com>
<HoAHJ.12386$1_.5423@fx37.iad> <tuBHJ.15393$jb4.14798@fx24.iad>
<86r18xlyqk.fsf@linuxsc.com> <_YFHJ.874$dV.864@fx44.iad>
<87r18wn1wd.fsf@nosuchdomain.example.com>
<L6UHJ.15869$mS1.11374@fx10.iad>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="88ea209702e7affaa0eb222d85ca1ed2";
logging-data="4519"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+8qOu8T2vXEAiSre2CCdAHWsknAZLo6p0="
Cancel-Lock: sha1:ebqmZ4nZKTAKfPKp3pU40pzDRqQ=
sha1:M2TU3uWhd/dM/N+/YaSLI0yB8Q8=
X-BSB-Auth: 1.68e93f2c2a5afc930757.20220125183059GMT.87lez31xcs.fsf@bsb.me.uk
 by: Ben Bacarisse - Tue, 25 Jan 2022 18:30 UTC

scott@slp53.sl.home (Scott Lurndal) writes:

> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>scott@slp53.sl.home (Scott Lurndal) writes:
>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>>scott@slp53.sl.home (Scott Lurndal) writes:
>>>>
>>>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>>>
>>>>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>>>>
>>>>>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>>>>>
>>>>>>> Surely you can find some example that wouldn't go against your
>>>>>>> existing agreements.
>>>>>
>>>>> Ok, a long C function: [...]
>>>>
>>>>Good, thank you for tracking down what looks like a good
>>>>example.
>>>>
>>>>Before I look any further, are there any particular aspects
>>>>you would say are important to pay attention to or that
>>>>contribute to difficulty in refactoring?
>>>
>>> Not really, other than that I believe this was derived
>>> from BSD at one point.
> ^^^
>>>
>>> Here's the helpers:
>>>
>>> #define NBBY 8 /* number of bits in a byte */
>>
>>Why not just use CHAR_BIT?
>
> Was CHAR_BIT available in 1983?

The code does not appear to date from 1983. You have 64-bit integers,
size_t, void, function prototypes, uintptr_t and doubtless other things
I've missed. In 1983 you could not even rely on what header to include
for strlen, malloc, varargs and so on, so for the original 1983-era code
you would not have been able to rely on anything in a header(!), but
clearly the code has been updated to use many post 1983 features.

--
Ben.

Re: How to avoid an overflow during multiplication?

<zpXHJ.7$h91.1@fx48.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20188&group=comp.lang.c#20188

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!border1.nntp.dca1.giganews.com!nntp.giganews.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx48.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: How to avoid an overflow during multiplication?
Newsgroups: comp.lang.c
References: <sqmkg9$157v$1@gioia.aioe.org> <86v8ydp57h.fsf@linuxsc.com> <ssehod$hfk$1@gioia.aioe.org> <9_BGJ.170561$X2_b.72894@fx09.ams4> <sseqsk$19vr$1@gioia.aioe.org> <pCCGJ.338776$6kH7.305209@fx03.ams4> <ssf045$19vr$2@gioia.aioe.org> <CCDGJ.246968$Gbad.173877@fx12.ams4> <86mtjopoq5.fsf@linuxsc.com> <RJWGJ.370432$tX27.294028@fx04.ams4> <86v8y9m8ba.fsf@linuxsc.com> <HoAHJ.12386$1_.5423@fx37.iad> <713da016-3175-4d0b-79b6-698d675c2e04@alumni.caltech.edu> <sspf9d$1877$1@gioia.aioe.org>
Lines: 59
Message-ID: <zpXHJ.7$h91.1@fx48.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Tue, 25 Jan 2022 18:35:11 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Tue, 25 Jan 2022 18:35:11 GMT
X-Received-Bytes: 3713
X-Original-Bytes: 3662
 by: Scott Lurndal - Tue, 25 Jan 2022 18:35 UTC

Manfred <invalid@invalid.add> writes:
>On 1/25/2022 3:50 AM, James Kuyper wrote:
>> On 1/24/22 11:24, Scott Lurndal wrote:
>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>> ...
>>>> This is comp.lang.c. My question is about C code, not C++ code.
>>>> C++ is a completely different animal.
>>
>> That's false, but so is the following:
>>
>>> No, it's just C with added capabilities.
>>
>> The C++ standard devotes 8 pages (C.5) to describing differences between
>> the way C and C++ handle a variety of issues, and another pair of pages
>> (C.6) that describe how the version of the C standard library that is
>> supported as part of the C++ standard library differs from the one
>> described by the C standard. That's not a lot out of a standard that
>> runs 1826 pages, but it not entirely negligible, either.
>>
>> Note that those lists do not include the features that C++ has that C
>> doesn't - they're about differences in the way that features shared
>> between the two languages work.
>>
>
>All true; it may also be worth recalling that this subthread is about
>justification of long functions, and that C++ was brought up in this
>comment:
>
>> ... In most cases, they were in bare-metal performance
>> critical code (operating systems, hypervisors) in C and C++.
>>
>> One in particular is the code to handle page table walks in
>> an ARM64 processor simulator. Another was handling the fork()
>> system call in a unix-derived MPP operating system. Both in C++.
>
>Now, it is one of the goals of C++ compared to C to be able to write
>more efficient and thus more compact code. I don't think C++ has failed
>in this respect - the criticism of those who favor C against C++ may be
>about complexity of the language, or lack of expressiveness in terms of
>clarity, but not being more verbose than C.
>
>In particular, with reference to the example posted elsethread,
>replacing long 'switch' blocks with more structured constructs is one
>typical refactoring when porting to C++.

Can you do that form of refactoring (specifically for a text
formatting function such as the implementation of printf posted
earlier) without sacrificing performance?

C++ basically sucks today if you use the output streams for
formatting instead of snprintf style format specifiers,
not to mention making maintenance (and L10N/I18N more complicated).

(note that the formatting example was used in a bare-metal
high-performance hypervisor on small supercomputer written
in C++. No libraries, no STL, no exceptions, no RTTI,
just C with classes - because every cycle wasted in the
hypervisor is not available to user code).

Re: How to avoid an overflow during multiplication?

<jEXHJ.10$h91.3@fx48.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20190&group=comp.lang.c#20190

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!npeer.as286.net!npeer-ng0.as286.net!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx48.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: How to avoid an overflow during multiplication?
Newsgroups: comp.lang.c
References: <sqmkg9$157v$1@gioia.aioe.org> <sseqsk$19vr$1@gioia.aioe.org> <pCCGJ.338776$6kH7.305209@fx03.ams4> <ssf045$19vr$2@gioia.aioe.org> <CCDGJ.246968$Gbad.173877@fx12.ams4> <86mtjopoq5.fsf@linuxsc.com> <RJWGJ.370432$tX27.294028@fx04.ams4> <86v8y9m8ba.fsf@linuxsc.com> <HoAHJ.12386$1_.5423@fx37.iad> <tuBHJ.15393$jb4.14798@fx24.iad> <86r18xlyqk.fsf@linuxsc.com> <_YFHJ.874$dV.864@fx44.iad> <87r18wn1wd.fsf@nosuchdomain.example.com> <L6UHJ.15869$mS1.11374@fx10.iad> <87lez31xcs.fsf@bsb.me.uk>
Lines: 48
Message-ID: <jEXHJ.10$h91.3@fx48.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Tue, 25 Jan 2022 18:50:55 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Tue, 25 Jan 2022 18:50:55 GMT
X-Received-Bytes: 2909
 by: Scott Lurndal - Tue, 25 Jan 2022 18:50 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>scott@slp53.sl.home (Scott Lurndal) writes:
>
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>>scott@slp53.sl.home (Scott Lurndal) writes:
>>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>>>scott@slp53.sl.home (Scott Lurndal) writes:
>>>>>
>>>>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>>>>
>>>>>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>>>>>
>>>>>>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>>>>>>
>>>>>>>> Surely you can find some example that wouldn't go against your
>>>>>>>> existing agreements.
>>>>>>
>>>>>> Ok, a long C function: [...]
>>>>>
>>>>>Good, thank you for tracking down what looks like a good
>>>>>example.
>>>>>
>>>>>Before I look any further, are there any particular aspects
>>>>>you would say are important to pay attention to or that
>>>>>contribute to difficulty in refactoring?
>>>>
>>>> Not really, other than that I believe this was derived
>>>> from BSD at one point.
>> ^^^
>>>>
>>>> Here's the helpers:
>>>>
>>>> #define NBBY 8 /* number of bits in a byte */
>>>
>>>Why not just use CHAR_BIT?
>>
>> Was CHAR_BIT available in 1983?
>
>The code does not appear to date from 1983. You have 64-bit integers,
>size_t, void, function prototypes, uintptr_t and doubtless other things
>I've missed. In 1983 you could not even rely on what header to include
>for strlen, malloc, varargs and so on, so for the original 1983-era code
>you would not have been able to rely on anything in a header(!), but
>clearly the code has been updated to use many post 1983 features.
>

The original for that came from BSD, probably 4.2ish. It was updated
to handle 64-bits when we ported it to the hypervisor 17 years ago.

Re: How to avoid an overflow during multiplication?

<875yq7mo8q.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20195&group=comp.lang.c#20195

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Tue, 25 Jan 2022 14:42:13 -0800
Organization: None to speak of
Lines: 47
Message-ID: <875yq7mo8q.fsf@nosuchdomain.example.com>
References: <sqmkg9$157v$1@gioia.aioe.org> <ssehod$hfk$1@gioia.aioe.org>
<9_BGJ.170561$X2_b.72894@fx09.ams4> <sseqsk$19vr$1@gioia.aioe.org>
<pCCGJ.338776$6kH7.305209@fx03.ams4> <ssf045$19vr$2@gioia.aioe.org>
<CCDGJ.246968$Gbad.173877@fx12.ams4> <86mtjopoq5.fsf@linuxsc.com>
<RJWGJ.370432$tX27.294028@fx04.ams4> <86v8y9m8ba.fsf@linuxsc.com>
<HoAHJ.12386$1_.5423@fx37.iad> <tuBHJ.15393$jb4.14798@fx24.iad>
<86r18xlyqk.fsf@linuxsc.com> <_YFHJ.874$dV.864@fx44.iad>
<87r18wn1wd.fsf@nosuchdomain.example.com>
<L6UHJ.15869$mS1.11374@fx10.iad>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="fbd031f938b902ca86c8b061f35a7f8c";
logging-data="14583"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ocOK05EI3AwLfFVPUJnkf"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:ZYUAQ1q3GXTWyh7BS9NgBJ5Nck0=
sha1:jHiwouPzyWvQyYLjFetrwhk0Ciw=
 by: Keith Thompson - Tue, 25 Jan 2022 22:42 UTC

scott@slp53.sl.home (Scott Lurndal) writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>scott@slp53.sl.home (Scott Lurndal) writes:
>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>>scott@slp53.sl.home (Scott Lurndal) writes:
>>>>
>>>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>>>
>>>>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>>>>
>>>>>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>>>>>
>>>>>>> Surely you can find some example that wouldn't go against your
>>>>>>> existing agreements.
>>>>>
>>>>> Ok, a long C function: [...]
>>>>
>>>>Good, thank you for tracking down what looks like a good
>>>>example.
>>>>
>>>>Before I look any further, are there any particular aspects
>>>>you would say are important to pay attention to or that
>>>>contribute to difficulty in refactoring?
>>>
>>> Not really, other than that I believe this was derived
>>> from BSD at one point.
> ^^^
>>>
>>> Here's the helpers:
>>>
>>> #define NBBY 8 /* number of bits in a byte */
>>
>>Why not just use CHAR_BIT?
>
> Was CHAR_BIT available in 1983?

Oh, *that* BSD, not one of its later derivatives! (I first used C under
BSD 4.1 myself.)

As others have mentioned, the code was updated to use newer features.
Replacing NBBY with CHAR_BIT would have made sense, but it's not a huge
deal.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: How to avoid an overflow during multiplication?

<Mm%HJ.1037$V31.65@fx47.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20196&group=comp.lang.c#20196

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx47.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: How to avoid an overflow during multiplication?
Newsgroups: comp.lang.c
References: <sqmkg9$157v$1@gioia.aioe.org> <pCCGJ.338776$6kH7.305209@fx03.ams4> <ssf045$19vr$2@gioia.aioe.org> <CCDGJ.246968$Gbad.173877@fx12.ams4> <86mtjopoq5.fsf@linuxsc.com> <RJWGJ.370432$tX27.294028@fx04.ams4> <86v8y9m8ba.fsf@linuxsc.com> <HoAHJ.12386$1_.5423@fx37.iad> <tuBHJ.15393$jb4.14798@fx24.iad> <86r18xlyqk.fsf@linuxsc.com> <_YFHJ.874$dV.864@fx44.iad> <87r18wn1wd.fsf@nosuchdomain.example.com> <L6UHJ.15869$mS1.11374@fx10.iad> <875yq7mo8q.fsf@nosuchdomain.example.com>
Lines: 50
Message-ID: <Mm%HJ.1037$V31.65@fx47.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Tue, 25 Jan 2022 23:05:16 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Tue, 25 Jan 2022 23:05:16 GMT
X-Received-Bytes: 2721
 by: Scott Lurndal - Tue, 25 Jan 2022 23:05 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>scott@slp53.sl.home (Scott Lurndal) writes:
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>>scott@slp53.sl.home (Scott Lurndal) writes:
>>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>>>scott@slp53.sl.home (Scott Lurndal) writes:
>>>>>
>>>>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>>>>
>>>>>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>>>>>
>>>>>>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>>>>>>
>>>>>>>> Surely you can find some example that wouldn't go against your
>>>>>>>> existing agreements.
>>>>>>
>>>>>> Ok, a long C function: [...]
>>>>>
>>>>>Good, thank you for tracking down what looks like a good
>>>>>example.
>>>>>
>>>>>Before I look any further, are there any particular aspects
>>>>>you would say are important to pay attention to or that
>>>>>contribute to difficulty in refactoring?
>>>>
>>>> Not really, other than that I believe this was derived
>>>> from BSD at one point.
>> ^^^
>>>>
>>>> Here's the helpers:
>>>>
>>>> #define NBBY 8 /* number of bits in a byte */
>>>
>>>Why not just use CHAR_BIT?
>>
>> Was CHAR_BIT available in 1983?
>
>Oh, *that* BSD, not one of its later derivatives! (I first used C under
>BSD 4.1 myself.)
>
>As others have mentioned, the code was updated to use newer features.
>Replacing NBBY with CHAR_BIT would have made sense, but it's not a huge
>deal.

Looks like they eliminated it in recent freebsd:

https://svnweb.freebsd.org/base/head/sys/kern/subr_prf.c?view=markup

starts at line 590.

Re: How to avoid an overflow during multiplication?

<86ee4qn1m2.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20277&group=comp.lang.c#20277

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sat, 29 Jan 2022 04:54:45 -0800
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <86ee4qn1m2.fsf@linuxsc.com>
References: <sqmkg9$157v$1@gioia.aioe.org> <sqq0lb$1g77$1@gioia.aioe.org> <86v8ydp57h.fsf@linuxsc.com> <ssehod$hfk$1@gioia.aioe.org> <9_BGJ.170561$X2_b.72894@fx09.ams4> <sseqsk$19vr$1@gioia.aioe.org> <pCCGJ.338776$6kH7.305209@fx03.ams4> <ssf045$19vr$2@gioia.aioe.org> <CCDGJ.246968$Gbad.173877@fx12.ams4> <86mtjopoq5.fsf@linuxsc.com> <RJWGJ.370432$tX27.294028@fx04.ams4> <86v8y9m8ba.fsf@linuxsc.com> <HoAHJ.12386$1_.5423@fx37.iad> <tuBHJ.15393$jb4.14798@fx24.iad> <86r18xlyqk.fsf@linuxsc.com> <_YFHJ.874$dV.864@fx44.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="8a9fc8cdb13989d258a574a29792b8b1";
logging-data="5862"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198op/MRbkO7cMPF1znpUdCPpvnkRQyJ4Q="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:R3EWUTsoreeb7SDh4pavYh/Eqjg=
sha1:5MD6pXxeJyFkgU2OCcgE0QUGx0k=
 by: Tim Rentsch - Sat, 29 Jan 2022 12:54 UTC

scott@slp53.sl.home (Scott Lurndal) writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> scott@slp53.sl.home (Scott Lurndal) writes:
>>
>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>
>>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>>
>>>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>>>
>>>>> Surely you can find some example that wouldn't go against your
>>>>> existing agreements.
>>>
>>> Ok, a long C function: [...]
>>
>> Good, thank you for tracking down what looks like a good
>> example.
>>
>> Before I look any further, are there any particular aspects
>> you would say are important to pay attention to or that
>> contribute to difficulty in refactoring?
>
> Not really, other than that I believe this was derived
> from BSD at one point.
>
> Here's the helpers: [...]

I got these, thank you. Additional comments in a followup
to your posting elsethread.

Re: How to avoid an overflow during multiplication?

<86a6femn7g.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20288&group=comp.lang.c#20288

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sat, 29 Jan 2022 10:05:55 -0800
Organization: A noiseless patient Spider
Lines: 98
Message-ID: <86a6femn7g.fsf@linuxsc.com>
References: <sqmkg9$157v$1@gioia.aioe.org> <86v8ydp57h.fsf@linuxsc.com> <ssehod$hfk$1@gioia.aioe.org> <9_BGJ.170561$X2_b.72894@fx09.ams4> <sseqsk$19vr$1@gioia.aioe.org> <pCCGJ.338776$6kH7.305209@fx03.ams4> <ssf045$19vr$2@gioia.aioe.org> <CCDGJ.246968$Gbad.173877@fx12.ams4> <86mtjopoq5.fsf@linuxsc.com> <RJWGJ.370432$tX27.294028@fx04.ams4> <86v8y9m8ba.fsf@linuxsc.com> <HoAHJ.12386$1_.5423@fx37.iad> <713da016-3175-4d0b-79b6-698d675c2e04@alumni.caltech.edu> <sspf9d$1877$1@gioia.aioe.org> <zpXHJ.7$h91.1@fx48.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="8a9fc8cdb13989d258a574a29792b8b1";
logging-data="16668"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19epnhsEBL0LnXRhXWv0rOde1/8tAI0tXQ="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:IXbJKNwChxg7pb1d4RiN32hYyH0=
sha1:4/D6r5c3Xz4zCwf2IM3kbSWLKqA=
 by: Tim Rentsch - Sat, 29 Jan 2022 18:05 UTC

scott@slp53.sl.home (Scott Lurndal) writes:

> Manfred <invalid@invalid.add> writes:
>
>> On 1/25/2022 3:50 AM, James Kuyper wrote:
>>
>>> On 1/24/22 11:24, Scott Lurndal wrote:
>>>
>>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>
>>> ...
>>>
>>>>> This is comp.lang.c. My question is about C code, not C++ code.
>>>>> C++ is a completely different animal.
>>>
>>> That's false, but so is the following:
>>>
>>>> No, it's just C with added capabilities.
>>>
>>> The C++ standard devotes 8 pages (C.5) to describing differences between
>>> the way C and C++ handle a variety of issues, and another pair of pages
>>> (C.6) that describe how the version of the C standard library that is
>>> supported as part of the C++ standard library differs from the one
>>> described by the C standard. That's not a lot out of a standard that
>>> runs 1826 pages, but it not entirely negligible, either.
>>>
>>> Note that those lists do not include the features that C++ has that C
>>> doesn't - they're about differences in the way that features shared
>>> between the two languages work.
>>
>> All true; it may also be worth recalling that this subthread is about
>> justification of long functions, and that C++ was brought up in this
>> comment:
>>
>>> ... In most cases, they were in bare-metal performance
>>> critical code (operating systems, hypervisors) in C and C++.
>>>
>>> One in particular is the code to handle page table walks in
>>> an ARM64 processor simulator. Another was handling the fork()
>>> system call in a unix-derived MPP operating system. Both in C++.
>>
>> Now, it is one of the goals of C++ compared to C to be able to write
>> more efficient and thus more compact code. I don't think C++ has failed
>> in this respect - the criticism of those who favor C against C++ may be
>> about complexity of the language, or lack of expressiveness in terms of
>> clarity, but not being more verbose than C.
>>
>> In particular, with reference to the example posted elsethread,
>> replacing long 'switch' blocks with more structured constructs is one
>> typical refactoring when porting to C++.
>
> Can you do that form of refactoring (specifically for a text
> formatting function such as the implementation of printf posted
> earlier) without sacrificing performance? [further C++ remarks
> omitted]

Writing in plain C, it isn't difficult to restructure the posted
printf-like code into multiple small or reasonably sized functions
(no more than 40ish lines, say). The effort needed isn't trivial
but it isn't really challenging either.

I'm intrigued by the phrase "without sacrificing performance". I
see no reason to suppose the performance of a restructured version
should be worse than that of the original. (Of course this means
on average; most likely some cases would be better and others
would be worse, but overall not significantly different.) So I'm
wondering why someone would think the performance of the original
is going to be better than refactored/restructured alternatives.

Looking at subr_prf.c (from the link posted elsethread) offers a
clue. The structure of that code is very nearly identical to the
code posted here. Looking at the copyright dates, it looks like
the subr_prf code was written between about 30 and 35 years ago.
At that time there were two significant differences relative to
today: processor behavior was less advanced, and compiler
technology was less sophisticated. Both of these trends make it
more likely that some performance advantage, if there was any, of
that earlier code would not accrue for more modern machines when
using more modern tools.

There are at least two other factors that weigh on the question.
One is workload: it is quite possible that alternative A would
give better performance than alternative B for one set of inputs,
and vice versa for a different set of inputs, and so which
alternative is better depends on what distribution of inputs is
expected. Another is operating context: these days performance
is highly multi-dimensional, being affected by all sorts of things
beyond just what sequence of instructions is executed. Here again
we might very well see a situation where alternative A is better
in one operating environment whereas alternative B is better in a
different operating environment. For both of these factors it
would be very unusual to see one alternative give better results
over all points in the space of plausible scenarios.

So it may be the case that the posted code would do better than
some proposed restructing, for its expected workload and intended
operating environment, etc. Without more specifics, however, the
proposition remains unconvincing.

Re: How to avoid an overflow during multiplication?

<86sfszlsfd.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=20322&group=comp.lang.c#20322

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Thu, 03 Feb 2022 10:24:22 -0800
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <86sfszlsfd.fsf@linuxsc.com>
References: <sqmkg9$157v$1@gioia.aioe.org> <8735m954yz.fsf@bsb.me.uk> <sqn0aq$1e8b$1@gioia.aioe.org> <unsigned-20211231144041@ram.dialup.fu-berlin.de> <sqn2dj$14ld$2@gioia.aioe.org> <877dbk36qu.fsf@nosuchdomain.example.com> <sqnmsm$1ff8$1@gioia.aioe.org> <sqo47m$n9p$1@dont-email.me> <sqq0lb$1g77$1@gioia.aioe.org> <86v8ydp57h.fsf@linuxsc.com> <ssehod$hfk$1@gioia.aioe.org> <86pmojo7th.fsf@linuxsc.com> <sslpp3$61s$2@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="efc7b42c7b44bc2df11a8d90378d7562";
logging-data="772"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195ABe8eD7GufgjtPk6N2B4wl/GcQ10HN8="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:3zA4W6KwuW4o4vyq9geYJEhFYyY=
sha1:RAsDaPIN3i0SogNwfyS/9CYtuWE=
 by: Tim Rentsch - Thu, 3 Feb 2022 18:24 UTC

Mateusz Viste <mateusz@xyz.invalid> writes:

> 2022-01-22 at 12:04 -0800, Tim Rentsch wrote:
>
>> To be explicit the above is not meant as an argument to convince
>> you. I am however interested in whatever reactions you might
>> have.
>
> My reaction is simply that in real world, there's no one ring to rule
> them all. Each of us has to choose the tools that suit him best, based
> on many things: the exact need at hand, personal preferences, and
> personal limitations to name only the few that come to mind immediately.

I am trying to understand the reasons for those preferences.

>> I have looked through the list of changes between C90 and C99 and
>> don't see anything else that looks objectionable. Can I ask you
>> to provide a more comprehensive list? I really am at a loss to
>> know what sorts of things you wouldn't like and also would be
>> tempted to use.
>
> It's not only about temptation, it also about using tools that are as
> simple as possible. I like games with simple rules - one reason why I
> prefer Go over chess. Some say it's because I lack brain power, and
> they may be right. [...]
>
> Now, about features that I don't like in C99:
> - VLAs (temptation argument again, that may lead to stack exhaustion)
> - bool (don't see what added value this brings)
> - complex & imaginary numbers (I admit those may be useful in some
> niche usage, but *I* never had such need)

With all due respect, these sound more like rationalizations than
reasons. Have you made any effort to discover changes and new
features in C99 that you would like? It's important to look at
both sides, advantages as well as disadvantages.

> [...] Now, C99 isn't *that* much of a complication that I
> couldn't grasp it, but then where do I draw the line? C89 (or its gnu
> dialect) works for me and allows me to do the jobs I need to do without
> pain, so why bother.

If you don't give C99 an earnest try of non-trivial duration,
you'll never know.

Pages:12345678
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor