Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The University of California Statistics Department; where mean is normal, and deviation standard.


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?

<sseq9h$p7v$1@gioia.aioe.org>

  copy mid

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

  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: Fri, 21 Jan 2022 18:25:05 +0100
Organization: . . .
Message-ID: <sseq9h$p7v$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="25855"; 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 - Fri, 21 Jan 2022 17:25 UTC

2022-01-21 at 18:14 +0100, David Brown wrote:
> > Entirely possible, yes, since I am not checking every line of my
> > code against the ANSI/ISO 9899-1990 reference book. :)
>
> You can use "-std=c90 -Wpedantic" to give warnings on most
> non-standard code. (If you are interested, of course.)

I know, and I use, but it's still quite tolerant. Even -Wall hides a
fair number of warnings. It's why lately I don't use gcc at all and
prefer relying on clang with its very cool -Weverything.

Mateusz

Re: How to avoid an overflow during multiplication?

<sseqf1$p7v$2@gioia.aioe.org>

  copy mid

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

  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: Fri, 21 Jan 2022 18:28:01 +0100
Organization: . . .
Message-ID: <sseqf1$p7v$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>
<ssepg1$2s3$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="25855"; 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 - Fri, 21 Jan 2022 17:28 UTC

2022-01-21 at 12:11 -0500, James Kuyper wrote:
> Many (most? all? - I haven't bothered to check.) of those are not gcc
> extensions, they're part of the POSIX standard library.

They are still extensions of C89 (mostly picked out from C99), hence
why I use -std=gnu89 in practice instead of the more puritan -std=c89.

Mateusz

Re: How to avoid an overflow during multiplication?

<sseqsk$19vr$1@gioia.aioe.org>

  copy mid

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

  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: Fri, 21 Jan 2022 18:35:15 +0100
Organization: . . .
Message-ID: <sseqsk$19vr$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>
<9_BGJ.170561$X2_b.72894@fx09.ams4>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="43003"; 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 - Fri, 21 Jan 2022 17:35 UTC

2022-01-21 at 17:23 GMT, Scott Lurndal wrote:
> >You are of course right, but that's not really the point. Let me
> >provide one example. In C99, it is legal to declare a variable that
> >is not at the top of the scope. Fine, but *I* don't like it, as I
> >find that it encourages sloppy programming.
>
> That hasn't been my experience.
>
> In fact, there are valid arguments for moving the
> declaration closer to the use, particularly in functions
> that may exit before using an initialized declaration.
>
> Either via a basic block (stand-alone or as part of a
> conditional or looping construct) or using C++/C99 features.

If you have such need, then it is likely that your functions are really
long. Maybe there are good reasons for it, but in my experience it is
more often than not the sign of a function that would better be
exploded into more, smaller, more specialized functions. I often miss it
myself, and I see it only when I realize that I have to scroll three
screens of text to figure out what the rowcount variable is about.

Mateusz

Re: How to avoid an overflow during multiplication?

<ssesak$oea$1@dont-email.me>

  copy mid

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

  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: Fri, 21 Jan 2022 12:59:48 -0500
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <ssesak$oea$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> <ssepg1$2s3$1@dont-email.me>
<sseqf1$p7v$2@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 21 Jan 2022 17:59:48 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="8394e4ea3cc8d045d83094d8fbfadf7c";
logging-data="25034"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/IqtK4Zmxue5LPJej39DIbqVEBJlox590="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:ddCFlSHhFuGhkG01dWtF8SGoEOo=
In-Reply-To: <sseqf1$p7v$2@gioia.aioe.org>
Content-Language: en-US
 by: James Kuyper - Fri, 21 Jan 2022 17:59 UTC

On 1/21/22 12:28 PM, Mateusz Viste wrote:
> 2022-01-21 at 12:11 -0500, James Kuyper wrote:
>> Many (most? all? - I haven't bothered to check.) of those are not gcc
>> extensions, they're part of the POSIX standard library.
>
> They are still extensions of C89 (mostly picked out from C99), hence
> why I use -std=gnu89 in practice instead of the more puritan -std=c89.

They are not compiler extensions, because they're not associated with
the compiler, nor are they associated with C99. A fully conforming
implementation of C running on a POSIX platform should accept the
following code even when running in strict C89 mode, without relying
upon any extensions:

#define _POSIX_C_SOURCE 2
#include <stdio.h>
int main()
{ FILE * file = popen("", "");
return 0;
}

Re: How to avoid an overflow during multiplication?

<pCCGJ.338776$6kH7.305209@fx03.ams4>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx03.ams4.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> <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> <9_BGJ.170561$X2_b.72894@fx09.ams4> <sseqsk$19vr$1@gioia.aioe.org>
Lines: 21
Message-ID: <pCCGJ.338776$6kH7.305209@fx03.ams4>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 21 Jan 2022 18:06:13 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 21 Jan 2022 18:06:13 GMT
X-Received-Bytes: 1950
 by: Scott Lurndal - Fri, 21 Jan 2022 18:06 UTC

Mateusz Viste <mateusz@xyz.invalid> writes:
>2022-01-21 at 17:23 GMT, Scott Lurndal wrote:
>> >You are of course right, but that's not really the point. Let me
>> >provide one example. In C99, it is legal to declare a variable that
>> >is not at the top of the scope. Fine, but *I* don't like it, as I
>> >find that it encourages sloppy programming.
>>
>> That hasn't been my experience.
>>
>> In fact, there are valid arguments for moving the
>> declaration closer to the use, particularly in functions
>> that may exit before using an initialized declaration.
>>
>> Either via a basic block (stand-alone or as part of a
>> conditional or looping construct) or using C++/C99 features.
>
>If you have such need, then it is likely that your functions are really
>long.

What does early exit (e.g. parameter validation) have to do
with overlong functions?

Re: How to avoid an overflow during multiplication?

<ssf045$19vr$2@gioia.aioe.org>

  copy mid

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

  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: Fri, 21 Jan 2022 20:04:37 +0100
Organization: . . .
Message-ID: <ssf045$19vr$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>
<9_BGJ.170561$X2_b.72894@fx09.ams4>
<sseqsk$19vr$1@gioia.aioe.org>
<pCCGJ.338776$6kH7.305209@fx03.ams4>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="43003"; 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 - Fri, 21 Jan 2022 19:04 UTC

2022-01-21 at 18:06 GMT, Scott Lurndal wrote:
> What does early exit (e.g. parameter validation) have to do
> with overlong functions?

What does parameter validation have to do with the position where
variables are declared?

Perhaps you could post a (very short) example of what you mean?
"function that may exit before using an initialized declaration" is
something that I handle as below, that's why I do not understand why
it's an argument for where what is declared. But show me your way
please so I can understand your point of view.

char *fn(int a) {
char *res = NULL;

if (a < 1) goto GAMEOVER;
res = malloc(a);
if (res == NULL) goto GAMEOVER;

return(res);

GAMEOVER:
free(res);
return(NULL);
}

Mateusz

Re: How to avoid an overflow during multiplication?

<CCDGJ.246968$Gbad.173877@fx12.ams4>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx12.ams4.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> <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> <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>
Lines: 31
Message-ID: <CCDGJ.246968$Gbad.173877@fx12.ams4>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 21 Jan 2022 19:14:42 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 21 Jan 2022 19:14:42 GMT
X-Received-Bytes: 2369
 by: Scott Lurndal - Fri, 21 Jan 2022 19:14 UTC

Mateusz Viste <mateusz@xyz.invalid> writes:
>2022-01-21 at 18:06 GMT, Scott Lurndal wrote:
>> What does early exit (e.g. parameter validation) have to do
>> with overlong functions?
>
>What does parameter validation have to do with the position where
>variables are declared?
>
>Perhaps you could post a (very short) example of what you mean?
>"function that may exit before using an initialized declaration" is
>something that I handle as below, that's why I do not understand why
>it's an argument for where what is declared. But show me your way
>please so I can understand your point of view.
>
>char *fn(int a) {
> char *res = NULL;
>
> if (a < 1) goto GAMEOVER;

So the initialization of res executes unnecessary instructions
to zero 8 bytes on the stack. Moving the declaration after the if statement
reduces the instruction count in that path. In certain functions, that can
make a difference in performance.

I once believed as you do, but the benefits of placing the
declaration closer to the use has many benefits and few
downsides.

And I've seen some pretty long functions that are not easily
amenable to factorization into smaller functions for structural
or performance reasons.

Re: How to avoid an overflow during multiplication?

<ssf2v1$baq$1@dont-email.me>

  copy mid

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

  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: Fri, 21 Jan 2022 20:53:04 +0100
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <ssf2v1$baq$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 21 Jan 2022 19:53:05 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4fc7355f81e96926aa9d1a822c6394e9";
logging-data="11610"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/nH9jQxDR/LZF1Y55aVq+nuWm/myjt/7I="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:LMbnx7Tzjct+l3gkdLJn3Ic1i5g=
In-Reply-To: <sseq9h$p7v$1@gioia.aioe.org>
Content-Language: en-GB
 by: David Brown - Fri, 21 Jan 2022 19:53 UTC

On 21/01/2022 18:25, Mateusz Viste wrote:
> 2022-01-21 at 18:14 +0100, David Brown wrote:
>>> Entirely possible, yes, since I am not checking every line of my
>>> code against the ANSI/ISO 9899-1990 reference book. :)
>>
>> You can use "-std=c90 -Wpedantic" to give warnings on most
>> non-standard code. (If you are interested, of course.)
>
> I know, and I use, but it's still quite tolerant. Even -Wall hides a
> fair number of warnings. It's why lately I don't use gcc at all and
> prefer relying on clang with its very cool -Weverything.
>

"-Wall" does not "hide" any warnings - it enables warnings. The name is
a bit of a misnomer - if you think of it as "enable warnings that all
reasonable code will pass without complaint", you have a better view
than if you think it enables all warnings. Remember, gcc is used as a
system compiler on many OS's, and has to strike a balance between
complaint-free compilation of existing (perhaps decades old) code that
has been used successfully with old compiler versions, and giving
helpful feedback to developers to aid them write correct code.

"-Wextra" enables many more warnings - with most developers disagreeing
about some of the warnings, but not agreeing on which ones they disagree
about. So expect some fine-tuning to suit your particular preferences
and needs. (For my own use, I start with "-Wall -Wextra" and have a
number of other options that I enable or disable.)

"-Wpedantic" is more specific - it attempts to be strict about warning
on anything that the C standards say should have a diagnostic, as well
as the use of any gcc extensions (if you have picked a non-extended
standard).

You might also like "-Wc90-c99-compat", which will warn about using
anything from C99 that was not in C90.

(No warning system is ever 100% free from false positives or false
negatives.)

clang's "-Weverything", as I understand it, was never intended to be
useful with real code. It is primarily for testing purposes.

Re: How to avoid an overflow during multiplication?

<875yqc3jge.fsf@bsb.me.uk>

  copy mid

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

  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: Fri, 21 Jan 2022 20:46:57 +0000
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <875yqc3jge.fsf@bsb.me.uk>
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> <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>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="0e6b72cf978bb09f81a0c149ca214240";
logging-data="4131"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/X5px5eSXjJ8lC0/9kSh4K2w5bc5jw+d4="
Cancel-Lock: sha1:E2Nkq/h03bDq4ZwQUak0bw+HM50=
sha1:p037+2QKu//P2coQQ0S5ya28FiY=
X-BSB-Auth: 1.7d745d454af00ecd725f.20220121204657GMT.875yqc3jge.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 21 Jan 2022 20:46 UTC

Mateusz Viste <mateusz@xyz.invalid> writes:

> 2022-01-21 at 18:06 GMT, Scott Lurndal wrote:
>> What does early exit (e.g. parameter validation) have to do
>> with overlong functions?
>
> What does parameter validation have to do with the position where
> variables are declared?
>
> Perhaps you could post a (very short) example of what you mean?
> "function that may exit before using an initialized declaration" is
> something that I handle as below, that's why I do not understand why
> it's an argument for where what is declared. But show me your way
> please so I can understand your point of view.
>
> char *fn(int a) {
> char *res = NULL;
>
> if (a < 1) goto GAMEOVER;
> res = malloc(a);
> if (res == NULL) goto GAMEOVER;
>
> return(res);
>
> GAMEOVER:
> free(res);
> return(NULL);
> }

As is so often the case with made-up examples, this raises more
questions than it answers. fn seems to me to be this:

char *fn(int a) {
if (a > 0)
return malloc(a);
return 0;
}

or, as I'd write it,

char *fn(int a) { return a > 0 ? malloc(a) : 0; }

Maybe there was some implied use of res before returning, so the
variable would be needed:

char *fn(int a) {
if (a > 0) {
char *res = malloc(a);
if (res) {
/* make use of res here before returning */
return res;
}
}
return 0;
}

but again, no need to initialise res anywhere but at the start of a
block.

Avoiding C99 mixed declarations and statements will, sometimes, require
an object to be initialised where it would not otherwise need to be, but
this code is not an example of that.

--
Ben.

Re: How to avoid an overflow during multiplication?

<ssf87g$19vr$3@gioia.aioe.org>

  copy mid

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

  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: Fri, 21 Jan 2022 22:22:56 +0100
Organization: . . .
Message-ID: <ssf87g$19vr$3@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>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="43003"; 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 - Fri, 21 Jan 2022 21:22 UTC

2022-01-21 at 20:53 +0100, David Brown wrote:
> "-Wall" does not "hide" any warnings - it enables warnings.

Yes, but not "all" of them. Some (many!) are still hidden. And I
understand the reasons, I just do not agree with them.

> clang's "-Weverything", as I understand it, was never intended to be
> useful with real code. It is primarily for testing purposes.

Perhaps, nonetheless *I* use it extensively in "real" code and I'm very
happy with it. Of course I do have to disable a few annoying warnings
sometimes (like the one about struct padding), but I prefer enabling all
and hand-pick what to ignore, rather than enabling a vague set of
defaults and then wonder what possibly I am missing.

The advantage of -Weverything is that when I upgrade clang, I get all
the newly added cool warnings immediately, without the need to study
clang's changelog in the matter. If I don't like the new additions - no
problem, I can easily disable them.

> You might also like "-Wc90-c99-compat", which will warn about using
> anything from C99 that was not in C90.

Sounds nice, sadly clang does not know it.

Mateusz

Re: How to avoid an overflow during multiplication?

<86mtjopoq5.fsf@linuxsc.com>

  copy mid

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

  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: Fri, 21 Jan 2022 17:02:10 -0800
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <86mtjopoq5.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> <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>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="434625eb2bdf5b21805d62a567edd212";
logging-data="31933"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Gs+jf0fdD6Dgg5xaBGdkRQ3LBE1m/nfU="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:afynJHzeZbmHTT3C8W6UbSDfgPU=
sha1:mewxMTy6ExsTaAdURwUxQibTkXA=
 by: Tim Rentsch - Sat, 22 Jan 2022 01:02 UTC

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.

Re: How to avoid an overflow during multiplication?

<867daspnbt.fsf@linuxsc.com>

  copy mid

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

  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: Fri, 21 Jan 2022 17:32:22 -0800
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <867daspnbt.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>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="434625eb2bdf5b21805d62a567edd212";
logging-data="31933"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/fYDlooyM0JOl83wfpN+iRGbrLNeRqZmI="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:zO2zXPiIUs4opnMPajZ5U45flTE=
sha1:j8YbGGait3a1HEQJAp9HPY6VVx4=
 by: Tim Rentsch - Sat, 22 Jan 2022 01:32 UTC

Mateusz Viste <mateusz@xyz.invalid> writes:

I'm responding in several parts to help keep the various
aspects separate.

> 2022-01-21 at 05:51 -0800, Tim Rentsch wrote:
>
>> I'm curious to know what extensions, if any, from the gnu
>> additions you make use of.
>
> That's an interesting question that I was unable to answer from the top
> of my head. It has been so long that I code in gnu89 that I wasn't able
> to tell what exactly is non-vanilla-C89 in the set of C features I use.
> To answer your question I took a couple of my projects and switched
> them from -std=gnu89 to -std=c89 to identify the gnu89 extensions that
> I use. [.. list to be addressed in subsequent followup ..]

That was interesting, thank you. Can I ask you to repeat the
experiment with -std=c89 -pedantic-errors (and no other warnings
or errors enabled) to see if that yields any additional items?
Also if it isn't too much bother, with -std=c99 -pedantic-errors.
I am most curious to see if anything else turns up (in either
of the tests).

Re: How to avoid an overflow during multiplication?

<8635lgp6fw.fsf@linuxsc.com>

  copy mid

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

  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: Fri, 21 Jan 2022 23:37:07 -0800
Organization: A noiseless patient Spider
Lines: 69
Message-ID: <8635lgp6fw.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>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="434625eb2bdf5b21805d62a567edd212";
logging-data="20807"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+SKMCgM0FU6ccg/CV7P7Im4Rnjc+36pcE="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:p3wMiUAf1v5bk00AhuRXWb7zpvE=
sha1:ICLGgFA8mXJOTffeHqefJ5LVSlU=
 by: Tim Rentsch - Sat, 22 Jan 2022 07:37 UTC

Mateusz Viste <mateusz@xyz.invalid> writes:

(Again I am responding in several parts to help keep the various
aspects separate.)

> 2022-01-21 at 05:51 -0800, Tim Rentsch wrote:
>
>> Also, I'm curious to know what extensions, if any, from the gnu
>> additions you make use of.
>
> [...] Here is [what was found]:
>
> __uint128_t (also uint64_t / uint32_t / uint8_t but it seems gcc
> tolerates those even in c89 mode, as long as stdint.h is included)
> struct timeval
> struct timespec
> DT_DIR / DT_REG
> PATH_MAX
>
> clock_gettime() / CLOCK_MONOTONIC
> select() / fd_set / FD_SET() / FD_ZERO() / FD_ISSET()
> strcasecmp()
> getaddrinfo() / freeaddrinfo() / struct addrinfo / gai_strerror()
> inet_aton()
> mrand48()
> snprintf() / vsnprintf()
> strdup()
> realpath()
> chroot()
> fileno()
> popen() / pclose()
> setenv() / unsetenv()
> vsyslog()

I think almost all of these can be made available, and fairly
easily, without having to resort to -std=gnuXX or general use of
any #defines of _XOPEN_SOURCE or similar symbols.

My usual practice is to put POSIX-related interfaces in a separate
file (eg, posix.h and posix.c), with only posix.c turning on any
needed extra functionality by using #define _XOPEN_SOURCE or
whatever.

Most of the interfaces listed above can be made available directly
through a posix.h header and used in standard-conforming C code. I
had no trouble making such a header for things like strdup, chroot,
setenv, and almost all the rest.

The macros for numeric constants cannot be supplied directly but
it isn't difficult to work around that aspect in various ways.

The various struct types can be used but only in pointer form
rather than directly. It's easy to work around that, if perhaps
somewhat tedious, by providing an abstract interface for those
types in posix.h (and posix.c implementing it).

The one problem child is select() and friends. My suggestion
there is to make a slightly higher level interface and used
that rather than using select() directly.

The motivation for doing all this is to get a program that is
almost exclusively purely standard conforming. The big problem
with using magic #defines or -std=gnuXX is like the proverbial
saying about a box of chocolates: you never know what you're
going to get. Worse, it can and sometimes does change between
different compiler releases. Localizing all that stuff to a
single .c file reduces the surface area of exposure and also
makes it easy to identify what non-standard interfaces are
being used and where.

Re: How to avoid an overflow during multiplication?

<ssggu0$9p4$1@gioia.aioe.org>

  copy mid

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

  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: Sat, 22 Jan 2022 09:57:36 +0100
Organization: . . .
Message-ID: <ssggu0$9p4$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>
<867daspnbt.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="10020"; 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 - Sat, 22 Jan 2022 08:57 UTC

2022-01-21 at 17:32 -0800, Tim Rentsch wrote:
> That was interesting, thank you. Can I ask you to repeat the
> experiment with -std=c89 -pedantic-errors

In fact that was the case already, albeit I use -pedantic in lieu of
-pedantic-errors to avoid stopping early if possible.

> Also if it isn't too much bother, with -std=c99 -pedantic-errors.

I didn't see any new errors. There was a lot less errors/warnings
overall, which is not surprising since c99 brings some of the
extensions present in gnu89. The fact that there was less warnings made
me spot two that I hadn't noticed earlier (although they are present
in both -c89 and -c99):

DT_LNK
initgroups()

So to answer your question: no, -c99 did not result in any new errors
compared to -c89. I wonder, though - why did you think it could? Isn't
c99 a superset of c89? The only possible reason I see is that when
compiling in -c89, make could abort earlier since it will stop at the
first module file in error, hence some of the C files won't even be
looked at. Is that what you thought about?

Mateusz

Re: How to avoid an overflow during multiplication?

<ssgrth$d2d$1@dont-email.me>

  copy mid

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

  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: Sat, 22 Jan 2022 13:05:04 +0100
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <ssgrth$d2d$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 22 Jan 2022 12:05:05 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ad037f383d9f25696d4b0eca1d3205b4";
logging-data="13389"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+eDk0/C9mbUnwboVMz14TrkMZpKVqHmVE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:WHTsPoeRrUI3JPTH7oHJJQKtW2k=
In-Reply-To: <ssf87g$19vr$3@gioia.aioe.org>
Content-Language: en-GB
 by: David Brown - Sat, 22 Jan 2022 12:05 UTC

On 21/01/2022 22:22, Mateusz Viste wrote:
> 2022-01-21 at 20:53 +0100, David Brown wrote:
>> "-Wall" does not "hide" any warnings - it enables warnings.
>
> Yes, but not "all" of them. Some (many!) are still hidden. And I
> understand the reasons, I just do not agree with them.
>
>> clang's "-Weverything", as I understand it, was never intended to be
>> useful with real code. It is primarily for testing purposes.
>
> Perhaps, nonetheless *I* use it extensively in "real" code and I'm very
> happy with it. Of course I do have to disable a few annoying warnings
> sometimes (like the one about struct padding), but I prefer enabling all
> and hand-pick what to ignore, rather than enabling a vague set of
> defaults and then wonder what possibly I am missing.
>
> The advantage of -Weverything is that when I upgrade clang, I get all
> the newly added cool warnings immediately, without the need to study
> clang's changelog in the matter. If I don't like the new additions - no
> problem, I can easily disable them.

You seem to imagine that compiler warnings invariably indicate a
problem, and that disabling (or not enabling) a warning hides errors in
your code. That is simply not true.

Some warnings cover things that are very probably a mistake. And some
handle things that were allowed in older C standards but are no longer
acceptable according to current standards - but the compiler by default
accepts them for convenience of using old code.

Others, however, are very much a matter of style and preference,
according to the needs of the programmer and the code. I, for example,
/do/ enable "-Wpadded" for my own code - but I do not expect the
majority of other users to want it.

I am a big fan of warning flags and static error checking in general.
But blinding saying "enable everything" is no more helpful than blindly
disabling everything. Either you have to write convoluted and strange
code to avoid tripping any warnings, or your compiler output will be
swamped with warning messages that don't indicate a real problem.

The situation gets even worse if you use more powerful third-party
linters without understanding them and picking the features and warnings
that make sense for your usage.

>
>> You might also like "-Wc90-c99-compat", which will warn about using
>> anything from C99 that was not in C90.
>
> Sounds nice, sadly clang does not know it.
>

clang and gcc each have their pros and cons.

Re: How to avoid an overflow during multiplication?

<ssguog$e4s$1@gioia.aioe.org>

  copy mid

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

  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: Sat, 22 Jan 2022 13:53:36 +0100
Organization: . . .
Message-ID: <ssguog$e4s$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="14492"; 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 - Sat, 22 Jan 2022 12:53 UTC

2022-01-22 at 13:05 +0100, David Brown wrote:
> You seem to imagine that compiler warnings invariably indicate a
> problem, and that disabling (or not enabling) a warning hides errors
> in your code. That is simply not true.

You are mistaken, I'm not imagining anything. I use -Weverything
because I like that the compiler warns me about things that he finds
odd. Sometimes it's an annoyance, but then it's easy to shut it by
instructing him not to check this specific warning. Other times it helps
finding a bug that would otherwise require a human to track it down.
Recent example: I got a warning about a shadowed variable (and it was
indeed a mistake). This warning is not present in -Wall nor -Wextra.

> Others, however, are very much a matter of style and preference,
> according to the needs of the programmer and the code. I, for
> example, /do/ enable "-Wpadded" for my own code - but I do not expect
> the majority of other users to want it.

That is definitely *not* a matter of style or preference. There are
situations where automatic struct padding is harmful, typically when
using said struct to communicate with other implementations. Such
padding might not occur on one compiler or architecture, but occurs on
another. Warning about that in this context is very much helpful.
Majority of my code does not rely on exact struct size and alignment,
hence for these scenarios I disable this check. But again - it's not at
all about style, it's strictly about what the structs are to be used
for, and this is something the compiler cannot guess.

> But blinding saying "enable everything" is no more helpful than
> blindly disabling everything.

I don't think that I ever said that I "blindly enable everything".

Mateusz

Re: How to avoid an overflow during multiplication?

<IGTGJ.5622$1_.3043@fx37.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!news.freedyn.de!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx37.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.5.0
Subject: Re: How to avoid an overflow during multiplication?
Content-Language: en-US
Newsgroups: comp.lang.c
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>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <ssguog$e4s$1@gioia.aioe.org>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 45
Message-ID: <IGTGJ.5622$1_.3043@fx37.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Sat, 22 Jan 2022 08:31:20 -0500
X-Received-Bytes: 3814
 by: Richard Damon - Sat, 22 Jan 2022 13:31 UTC

On 1/22/22 7:53 AM, Mateusz Viste wrote:
> 2022-01-22 at 13:05 +0100, David Brown wrote:
>> You seem to imagine that compiler warnings invariably indicate a
>> problem, and that disabling (or not enabling) a warning hides errors
>> in your code. That is simply not true.
>
> You are mistaken, I'm not imagining anything. I use -Weverything
> because I like that the compiler warns me about things that he finds
> odd. Sometimes it's an annoyance, but then it's easy to shut it by
> instructing him not to check this specific warning. Other times it helps
> finding a bug that would otherwise require a human to track it down.
> Recent example: I got a warning about a shadowed variable (and it was
> indeed a mistake). This warning is not present in -Wall nor -Wextra.
>
>> Others, however, are very much a matter of style and preference,
>> according to the needs of the programmer and the code. I, for
>> example, /do/ enable "-Wpadded" for my own code - but I do not expect
>> the majority of other users to want it.
>
> That is definitely *not* a matter of style or preference. There are
> situations where automatic struct padding is harmful, typically when
> using said struct to communicate with other implementations. Such
> padding might not occur on one compiler or architecture, but occurs on
> another. Warning about that in this context is very much helpful.
> Majority of my code does not rely on exact struct size and alignment,
> hence for these scenarios I disable this check. But again - it's not at
> all about style, it's strictly about what the structs are to be used
> for, and this is something the compiler cannot guess.
>
>> But blinding saying "enable everything" is no more helpful than
>> blindly disabling everything.
>
> I don't think that I ever said that I "blindly enable everything".
>
>
> Mateusz
>

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.

Re: How to avoid an overflow during multiplication?

<ssh5pb$1sp1$1@gioia.aioe.org>

  copy mid

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

  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: Sat, 22 Jan 2022 15:53:31 +0100
Organization: . . .
Message-ID: <ssh5pb$1sp1$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="62241"; 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 - Sat, 22 Jan 2022 14:53 UTC

2022-01-22 at 08:31 -0500, Richard Damon wrote:
> 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.

Yes, I know those and they are indeed about style, or even "code
religion". In the same register are the warnings about fall-through
case statements in a switch (I do not disable these warnings, though, as
95% of my switches are meant NOT to fall-through, and for the rest of
cases I write a proper comment next to it so clang is happy - and I
find it's actually a very good practice).

Anyway - yes, you are right, but David chose a very unfortunate example
and I was responding specifically to that.

Mateusz

Re: How to avoid an overflow during multiplication?

<ssh8t4$3mp$1@dont-email.me>

  copy mid

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

  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: Sat, 22 Jan 2022 16:46:43 +0100
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <ssh8t4$3mp$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 22 Jan 2022 15:46:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ad037f383d9f25696d4b0eca1d3205b4";
logging-data="3801"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BPx0zMC/1BfoL1c3VEzYRka2+xur3nok="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:Pso200x1+uPpC8kJqt4FoygWcE8=
In-Reply-To: <ssh5pb$1sp1$1@gioia.aioe.org>
Content-Language: en-GB
 by: David Brown - Sat, 22 Jan 2022 15:46 UTC

On 22/01/2022 15:53, Mateusz Viste wrote:
> 2022-01-22 at 08:31 -0500, Richard Damon wrote:
>> 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.
>
> Yes, I know those and they are indeed about style, or even "code
> religion". In the same register are the warnings about fall-through
> case statements in a switch (I do not disable these warnings, though, as
> 95% of my switches are meant NOT to fall-through, and for the rest of
> cases I write a proper comment next to it so clang is happy - and I
> find it's actually a very good practice).
>
> Anyway - yes, you are right, but David chose a very unfortunate example
> and I was responding specifically to that.
>

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.

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.

If you need to be sure of that a struct is the size you expect and need,
you can add padding manually and use _Static_assert (or a macro-based
alternative for older C standards) to check the size at compile-time.
Some care is always needed if the code must be portable, as type sizes
and alignments may vary according to the target.

If you don't care about the padding and find that the warning is being
triggered, you can still add the padding manually, or ignore the
warning, or disable it temporarily. (gcc and clang have pragmas for that.)

Re: How to avoid an overflow during multiplication?

<RJWGJ.370432$tX27.294028@fx04.ams4>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx04.ams4.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> <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>
Lines: 23
Message-ID: <RJWGJ.370432$tX27.294028@fx04.ams4>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sat, 22 Jan 2022 16:59:29 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sat, 22 Jan 2022 16:59:29 GMT
X-Received-Bytes: 2086
 by: Scott Lurndal - Sat, 22 Jan 2022 16:59 UTC

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. 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++.

See, for example, the pseudocode for AArch64.S1Translate in
ARM's DDI0487G_b on page J1-8110.

The C++ version of that is templated to handle both S1 and S2 table walks.

Re: How to avoid an overflow during multiplication?

<86y237oecd.fsf@linuxsc.com>

  copy mid

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

  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, 22 Jan 2022 09:44:02 -0800
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <86y237oecd.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> <867daspnbt.fsf@linuxsc.com> <ssggu0$9p4$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="434625eb2bdf5b21805d62a567edd212";
logging-data="22694"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2c1LeZmCh6x5elUgO47H8bfPJOzr+2sg="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:Vn7b5yNykNt1PEHkFt2PqLBQFRk=
sha1:zgPUaMmrYBZ4QDtmgNEpWFZapfQ=
 by: Tim Rentsch - Sat, 22 Jan 2022 17:44 UTC

Mateusz Viste <mateusz@xyz.invalid> writes:

> 2022-01-21 at 17:32 -0800, Tim Rentsch wrote:
>
>> That was interesting, thank you. Can I ask you to repeat the
>> experiment with -std=c89 -pedantic-errors
>
> In fact that was the case already, albeit I use -pedantic in lieu of
> -pedantic-errors to avoid stopping early if possible.
>
>> Also if it isn't too much bother, with -std=c99 -pedantic-errors.
>
> I didn't see any new errors. There was a lot less errors/warnings
> overall, which is not surprising since c99 brings some of the
> extensions present in gnu89. The fact that there was less warnings made
> me spot two that I hadn't noticed earlier (although they are present
> in both -c89 and -c99):
>
> DT_LNK
> initgroups()

Both of these are amenable to the posix.h scheme I mentioned in
my earlier posting. Also, after a bit more investigation, I
discovered select() is not the problem I thought it was; an
interface for select() can be provided in the same way as the other
functions, including FD_CLR etc (although for clients these will
be function calls rather than macros).

> So to answer your question: no, -c99 did not result in any new errors
> compared to -c89. I wonder, though - why did you think it could? Isn't
> c99 a superset of c89? [...]

My question was mostly about whether -pedantic would add anything.
However, there are constructs that are legal in C89/C90 but in C99
are constraint violations. There aren't many of these, and mostly
I expect they would not come up, but I thought it worth asking the
question.

> The only possible reason I see is that when
> compiling in -c89, make could abort earlier since it will stop at the
> first module file in error, hence some of the C files won't even be
> looked at. Is that what you thought about?

No, I was unconsciously assuming that you would manage your
build process well enough so that there wouldn't be any
problems along these lines.

Re: How to avoid an overflow during multiplication?

<86tudvodft.fsf@linuxsc.com>

  copy mid

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

  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, 22 Jan 2022 10:03:34 -0800
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <86tudvodft.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> <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>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="434625eb2bdf5b21805d62a567edd212";
logging-data="22694"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183v2yInv3gfPL8tXjDxU9tr/l0V4n0eMw="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:ppqwsZgxd0hcQ87BvZ/9terOlm0=
sha1:x1emcGILcaXo6EZb8a4HnlL+yaU=
 by: Tim Rentsch - Sat, 22 Jan 2022 18:03 UTC

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.

Re: How to avoid an overflow during multiplication?

<86pmojo7th.fsf@linuxsc.com>

  copy mid

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

  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, 22 Jan 2022 12:04:58 -0800
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <86pmojo7th.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>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="434625eb2bdf5b21805d62a567edd212";
logging-data="17819"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19TkBIovnL8CgBVGwuf8uO2GxLBFsJ2Jjw="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:je7J9JXKmq9brqZaIMjfVnyuh3A=
sha1:djNnPIqXoFTgpYHFmqVaZTOKK1Y=
 by: Tim Rentsch - Sat, 22 Jan 2022 20:04 UTC

Mateusz Viste <mateusz@xyz.invalid> writes:

(Again I am responding in several parts to help keep the various
aspects separate. This posting is the last of three.)

> 2022-01-21 at 05:51 -0800, Tim Rentsch wrote:
>
>> Can you say what you think the downside is of using C99? If
>> there are parts of C99 you don't like you can always just not
>> use them.
>
> You are of course right, but that's not really the point. Let me
> provide one example. In C99, it is legal to declare a variable that
> is not at the top of the scope. Fine, but *I* don't like it, as I
> find that it encourages sloppy programming. If I'm allowed to use
> something and it appears to be easier on the short term, I will most
> probably abuse it. Yes, I am a feeble human. C89 is a way to keep
> my laziness in check: all variables have to be at the top of the
> scope so I can see them upfront. If it starts to be messy, then it
> is because my scope needs to be refactored.

I share your distaste for mixing declarations and code, including
the part about sometimes being tempted to use it. Despite that,
I find C99 a non-trivial improvement over C89/C90. There are a
few constructs (not many, just a few) that are legal in C89/C90
(mainly for historical reasons) but require warnings in C99, and
that's good. Beyond that, C99 has compound literals, designated
initializers, more liberal rules for initializing structs and
arrays, // comments, long long integer types, and a variety of
other useful additions. Yes I know you can get some of these
under -std=gnu89, but then you get all sorts of other stuff that
is unknown and purely under the whim of GNU or clang or whoever.
I've been bitten in the past by letting in these extra and
unknown options, and it caused some difficulties. These days my
C code is strictly limited to standard-conforming code unless
there is a specific deliberate exception, and those are always
restricted to as narrow a scope as feasible. For me the benefit
of not allowing any non-standard functionality in the code
definitely outweighs the inconvenience of being tempted to use
intra-code declarations.

To be explicit the above is not meant as an argument to convince
you. I am however interested in whatever reactions you might
have.

> That's only one simple example, but I hope it conveys the larger
> idea.

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.

Re: How to avoid an overflow during multiplication?

<sshpag$qsh$1@dont-email.me>

  copy mid

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

  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: Sat, 22 Jan 2022 15:26:55 -0500
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <sshpag$qsh$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> <867daspnbt.fsf@linuxsc.com>
<ssggu0$9p4$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 22 Jan 2022 20:26:56 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="dbae1492b85e78a8d748e7d245fceb20";
logging-data="27537"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ZDU0U35M+MAMpAwwOPFeS5eOILdH4/08="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:stU+09QG6k7f2ihyKapXpWcuY2k=
In-Reply-To: <ssggu0$9p4$1@gioia.aioe.org>
Content-Language: en-US
 by: James Kuyper - Sat, 22 Jan 2022 20:26 UTC

On 1/22/22 03:57, Mateusz Viste wrote:
....
> So to answer your question: no, -c99 did not result in any new errors
> compared to -c89. I wonder, though - why did you think it could? Isn't
> c99 a superset of c89?

No. It come close, but there were several changes that could negatively
affect strictly conforming C89 code:

* Removal of implicit int.
* In C89, it was implementation-defined whether integer division rounded
toward 0 or toward negative infinity; in C90, it's required to round
toward 0.
* // comments can change the interpretation of certain unlikely
combinations, that were previously used as a way of detecting whether
you were translating the code as C or as C++:
* New rules for the types of integer constants and the integer
promotions can change the results of certain expressions.
* return without expression not permitted in function that returns a
value (and vice versa)'
* 'restrict' used to be an unreserved name, and as such could be used in
user code. Now it's a keyword.

Re: How to avoid an overflow during multiplication?

<86lez7o0et.fsf@linuxsc.com>

  copy mid

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

  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, 22 Jan 2022 14:44:58 -0800
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <86lez7o0et.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> <867daspnbt.fsf@linuxsc.com> <ssggu0$9p4$1@gioia.aioe.org> <sshpag$qsh$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="434625eb2bdf5b21805d62a567edd212";
logging-data="17528"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX189lLr5ya3NS/WHNS2x+SEZYF1cZzJ5ZkI="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:ouGrlHHAIV9+mwWexCZy8pxCfGg=
sha1:2x7AZSEKE2vfnnUeFCA8ySIAI/k=
 by: Tim Rentsch - Sat, 22 Jan 2022 22:44 UTC

James Kuyper <jameskuyper@alumni.caltech.edu> writes:

> On 1/22/22 03:57, Mateusz Viste wrote:
> ...
>
>> So to answer your question: no, -c99 did not result in any new errors
>> compared to -c89. I wonder, though - why did you think it could? Isn't
>> c99 a superset of c89?
>
> No. It come close, but there were several changes that could negatively
> affect strictly conforming C89 code:
>
> * Removal of implicit int.
> * In C89, it was implementation-defined whether integer division rounded
> toward 0 or toward negative infinity; in C90, it's required to round
> toward 0.
> * // comments can change the interpretation of certain unlikely
> combinations, that were previously used as a way of detecting whether
> you were translating the code as C or as C++:
> * New rules for the types of integer constants and the integer
> promotions can change the results of certain expressions.
> * return without expression not permitted in function that returns a
> value (and vice versa)'
> * 'restrict' used to be an unreserved name, and as such could be used in
> user code. Now it's a keyword.

Good list.

In addition, C89/C90 allows implicit function declaration, but
C99 does not. Also, in C99 'inline' is a keyword, but was not
in C89/C90.

Pages:12345678
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor