Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Were there no women, men might live like gods." -- Thomas Dekker


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?

<stqkdo$go3$3@gioia.aioe.org>

  copy mid

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

  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, 7 Feb 2022 09:14:48 +0100
Organization: . . .
Message-ID: <stqkdo$go3$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>
<86pmojo7th.fsf@linuxsc.com>
<sslpp3$61s$2@gioia.aioe.org>
<86sfszlsfd.fsf@linuxsc.com>
<sthe7t$1cph$1@gioia.aioe.org>
<sthkum$5nu$2@dont-email.me>
<sthm4i$d2b$1@gioia.aioe.org>
<stpgso$op1$1@dont-email.me>
<stqk7g$go3$1@gioia.aioe.org>
<stqkc4$go3$2@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="17155"; 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, 7 Feb 2022 08:14 UTC

2022-02-07 at 09:13 +0100, Mateusz Viste wrote:
> 2022-02-07 at 09:11 +0100, Mateusz Viste wrote:
> > 2022-02-06 at 22:08 +0000, Vir Campestris wrote:
> > > bool lets the compiler pick a type where the architecture can
> > > store 2 values easily.
> > >
> > > int_fast8_t is only convenient on machines that have hardware
> > > byte support. OK, that's most of them, but by no means all.
> >
> > int_fast8_t is convenient on machines that have hardware support for
> > anything that is at least 8 bits large.
> ^^
> (should have been "16" obviously) :)

(no it shouldn't, I will stop posting before the morning coffee now)

Mateusz

Re: How to avoid an overflow during multiplication?

<867da7jbxc.fsf@linuxsc.com>

  copy mid

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

  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, 07 Feb 2022 00:52:47 -0800
Organization: A noiseless patient Spider
Lines: 97
Message-ID: <867da7jbxc.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> <86sfszlsfd.fsf@linuxsc.com> <sthe7t$1cph$1@gioia.aioe.org> <sthkum$5nu$2@dont-email.me> <sthm4i$d2b$1@gioia.aioe.org> <sti5s0$dtj$1@dont-email.me> <6f966456-55d7-40f4-9815-25096cd2c709n@googlegroups.com> <stisri$195u$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="792c2a82c28252afd7e8a94f82466189";
logging-data="1365"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18wTkSpRxHOEPz0ibygn9sAYyzpsL7jQOU="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:8mKvEWWoqL5mwM4/BnPAAot4YGU=
sha1:9/fm/d76EY7Jx6WL9yHnUOkepkc=
 by: Tim Rentsch - Mon, 7 Feb 2022 08:52 UTC

Mateusz Viste <mateusz@xyz.invalid> writes:

> 2022-02-04 at 00:36 -0800, Tiib wrote:
>
>> That bool has only two values was already said above. It feels
>> tautological that more constrained type brings less opportunities
>> of misuse and so less cases to check or to unit test. I do not
>> know why it is not perceived as an advantage by some people or why
>> they get offended like if they were accused or suspected of misuse
>> by providing such benefit.
>
> You are right of course. Having an emulated "1-bit" type is, in
> theory, providing a nice way to handle values that are expected to
> be binary in nature.
>
> What I am wondering about is the practical use of it - ie. in
> what kind of situation such _Bool type could save the day. I am
> certainly biased, since I always used normal integer to keep
> flags, so I am genuinely interested to see how other people do.
> [...]

Consider the following code excerpt

enum {
FLAG_X = 1,
FLAG_Y = 2,
FLAG_Z = 4,
... etc ...
};

...

unsigned flags;

...

if( flags & FLAG_Y ) .. something ...

The purpose of _Bool is to hold the value of an expression in
just the same way that the expression would give in a logical
context such as if(), while(), do ... while(), or the middle
expression of for(). If for some reason we want to reuse or
hold on to the value of the expression inside an if() test,
using _Bool provides a good way to do that:

_Bool flag_y = flags & FLAG_Y;

I am something of an "old school" C programmer. If 'p' is a
pointer variable, I don't mind writing (and in fact often
prefer writing)

if( p ) ...

rather than the more verbose

if( p != NULL ) ...

Using _Bool works here too:

_Bool p_valid = p;

The conversion to _Bool converts null pointers to 0, and non-null
pointers to 1.

One reason we might want to save logical values in a variable is
to be able to combine logical expressions conveniently, without
needing to write out the '!= 0' that is implicit in logical
contexts. Also, because each _Bool is guaranteed to hold either
0 or 1 and nothing else, they can be combined using &, ^, and |
(if that is wanted) rather than && and || (and who knows what for
exclusive or). Of course I'm a big fan of && and ||, and tend to
use them more often than the bitwise & and |, but occasionally &,
^, and | do a better job of conveying how I think about the
conditions involved.

Another situation where I have found _Bool useful is inside
structs that hold lots of logical values. Rather use ordinary
members, logical values can be held in _Bool bitfields:

struct whatever {
_Bool property_a : 1;
_Bool property_b : 1;
_Bool property_c : 1;
/* etc */
};

Bitfields of type _Bool have the same "logical value" behavior
that regular _Bool variables have, namely converting any scalar
quantity to _Bool gives 1 if the converted quantity compares
not equal to 0, and 0 otherwise.

IME _Bool works well for most variables that are meant to hold a
logical value. Moreover if _Bool is not used then there is the
awkward question of what type to use instead. I wouldn't go so
far as to say that _Bool should be used for all such variables
and without exception, but in most cases it does seem to provide
a better fit than the other integer types.

Re: How to avoid an overflow during multiplication?

<stqqol$qho$1@dont-email.me>

  copy mid

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

  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: Mon, 7 Feb 2022 10:03:01 +0000
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <stqqol$qho$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> <86pmojo7th.fsf@linuxsc.com>
<sslpp3$61s$2@gioia.aioe.org> <86sfszlsfd.fsf@linuxsc.com>
<sthe7t$1cph$1@gioia.aioe.org> <sthkum$5nu$2@dont-email.me>
<sthm4i$d2b$1@gioia.aioe.org> <sti5s0$dtj$1@dont-email.me>
<6f966456-55d7-40f4-9815-25096cd2c709n@googlegroups.com>
<stisri$195u$1@gioia.aioe.org> <867da7jbxc.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 7 Feb 2022 10:03:01 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a49d5866c5cd5080c54467f0429e30c0";
logging-data="27192"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+gOJEW/RNc8QED1w8hLxIG26T6u1zyGy4="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:5/iC1F0aDuEzAJnuUmO3qkoHK/Y=
In-Reply-To: <867da7jbxc.fsf@linuxsc.com>
 by: Bart - Mon, 7 Feb 2022 10:03 UTC

On 07/02/2022 08:52, Tim Rentsch wrote:

> Using _Bool works here too:
>
> _Bool p_valid = p;
>
> The conversion to _Bool converts null pointers to 0, and non-null
> pointers to 1.

This leads to:

_Bool b;

b = &b;

which looks unintuitive. Usually the LHS would be of type T, then the
RHS would have the incompatible type T*

Re: How to avoid an overflow during multiplication?

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

  copy mid

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

  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: Mon, 07 Feb 2022 11:22:25 +0000
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <87y22mq5u6.fsf@bsb.me.uk>
References: <sqmkg9$157v$1@gioia.aioe.org> <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> <86sfszlsfd.fsf@linuxsc.com>
<sthe7t$1cph$1@gioia.aioe.org> <sthkum$5nu$2@dont-email.me>
<sthm4i$d2b$1@gioia.aioe.org> <sti5s0$dtj$1@dont-email.me>
<6f966456-55d7-40f4-9815-25096cd2c709n@googlegroups.com>
<stisri$195u$1@gioia.aioe.org> <867da7jbxc.fsf@linuxsc.com>
<stqqol$qho$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="059df472b84794aafc727c58745aa8a0";
logging-data="24171"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NlkJT4RLQo6ZvZoC7+jLWx+e9FRw8Bgs="
Cancel-Lock: sha1:51p9qgRE/D/VhbWnHaX11iu59RE=
sha1:4voFi4MB2AYxN21GHBwsTkZjhvI=
X-BSB-Auth: 1.6f07ad93f3c373a6a86f.20220207112225GMT.87y22mq5u6.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 7 Feb 2022 11:22 UTC

Bart <bc@freeuk.com> writes:

> On 07/02/2022 08:52, Tim Rentsch wrote:
>
>> Using _Bool works here too:
>> _Bool p_valid = p;
>> The conversion to _Bool converts null pointers to 0, and non-null
>> pointers to 1.
>
> This leads to:
>
> _Bool b;
>
> b = &b;
>
> which looks unintuitive. Usually the LHS would be of type T, then the
> RHS would have the incompatible type T*

That's an unwarranted intuition:

void *p;
p = &p;

--
Ben.

Re: How to avoid an overflow during multiplication?

<strc1t$n7q$1@dont-email.me>

  copy mid

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

  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: Mon, 7 Feb 2022 14:58:04 +0000
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <strc1t$n7q$1@dont-email.me>
References: <sqmkg9$157v$1@gioia.aioe.org> <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> <86sfszlsfd.fsf@linuxsc.com>
<sthe7t$1cph$1@gioia.aioe.org> <sthkum$5nu$2@dont-email.me>
<sthm4i$d2b$1@gioia.aioe.org> <sti5s0$dtj$1@dont-email.me>
<6f966456-55d7-40f4-9815-25096cd2c709n@googlegroups.com>
<stisri$195u$1@gioia.aioe.org> <867da7jbxc.fsf@linuxsc.com>
<stqqol$qho$1@dont-email.me> <87y22mq5u6.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 7 Feb 2022 14:58:05 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a49d5866c5cd5080c54467f0429e30c0";
logging-data="23802"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19rs3EcXZlKoLcBb/qxzn54fHspbQMGk14="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:qswURQpdzcRH8ALWBYrNNvX2xAY=
In-Reply-To: <87y22mq5u6.fsf@bsb.me.uk>
 by: Bart - Mon, 7 Feb 2022 14:58 UTC

On 07/02/2022 11:22, Ben Bacarisse wrote:
> Bart <bc@freeuk.com> writes:
>
>> On 07/02/2022 08:52, Tim Rentsch wrote:
>>
>>> Using _Bool works here too:
>>> _Bool p_valid = p;
>>> The conversion to _Bool converts null pointers to 0, and non-null
>>> pointers to 1.
>>
>> This leads to:
>>
>> _Bool b;
>>
>> b = &b;
>>
>> which looks unintuitive. Usually the LHS would be of type T, then the
>> RHS would have the incompatible type T*
>
> That's an unwarranted intuition:
>
> void *p;
> p = &p;

OK, there's that, although at least both sides are pointers to
something. A void target on either side makes both targets compatible.

I first came across this behaviour of _Bool in code that I think was
passing the address of a struct to a function expecting a _Bool
argument. It was rather puzzling (apart from the fact that the address
of a struct instance would always be true).

An explicit conversion (for example using !! on the argument, where the
0/1 result is a more reasonable value to pass to a _Bool parameter)
would have made things clearer.

Re: How to avoid an overflow during multiplication?

<86pmnyip2o.fsf@linuxsc.com>

  copy mid

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

  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, 07 Feb 2022 09:06:23 -0800
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <86pmnyip2o.fsf@linuxsc.com>
References: <sqmkg9$157v$1@gioia.aioe.org> <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> <86sfszlsfd.fsf@linuxsc.com> <sthe7t$1cph$1@gioia.aioe.org> <sthkum$5nu$2@dont-email.me> <sthm4i$d2b$1@gioia.aioe.org> <sti5s0$dtj$1@dont-email.me> <6f966456-55d7-40f4-9815-25096cd2c709n@googlegroups.com> <stisri$195u$1@gioia.aioe.org> <867da7jbxc.fsf@linuxsc.com> <stqqol$qho$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="792c2a82c28252afd7e8a94f82466189";
logging-data="18554"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ZWfrhilPTqXh77eoniYgkAUVcBo9MDzM="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:aJE1ToUx1q1D0zjvPBOmWo+mF9w=
sha1:N1czkz7nwL9dJMJaZjPgVda4Kv8=
 by: Tim Rentsch - Mon, 7 Feb 2022 17:06 UTC

Bart <bc@freeuk.com> writes:

> On 07/02/2022 08:52, Tim Rentsch wrote:
>
>> Using _Bool works here too:
>>
>> _Bool p_valid = p;
>>
>> The conversion to _Bool converts null pointers to 0, and non-null
>> pointers to 1.
>
> This leads to:
>
> _Bool b;
>
> b = &b;
>
> which looks unintuitive. Usually the LHS would be of type T, then the
> RHS would have the incompatible type T*

It is querelis gratia querimonia as usual, I see.

(With apologies to my high school Latin teacher. I never
was good at Latin.)

Re: How to avoid an overflow during multiplication?

<sts3p3$gpj$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: vir.camp...@invalid.invalid (Vir Campestris)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Mon, 7 Feb 2022 21:42:58 +0000
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <sts3p3$gpj$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> <86pmojo7th.fsf@linuxsc.com>
<sslpp3$61s$2@gioia.aioe.org> <86sfszlsfd.fsf@linuxsc.com>
<sthe7t$1cph$1@gioia.aioe.org> <sthkum$5nu$2@dont-email.me>
<sthm4i$d2b$1@gioia.aioe.org> <stpgso$op1$1@dont-email.me>
<stqk7g$go3$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 7 Feb 2022 21:42:59 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="2434b91cfc91b343e2eaf91e145d15ed";
logging-data="17203"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+SRS+ph5CernDcC/zFXK9Slhp8XjJIrA4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:WZ5Q+nlZEjWr+/z2VMpmNrUMtVM=
In-Reply-To: <stqk7g$go3$1@gioia.aioe.org>
Content-Language: en-GB
 by: Vir Campestris - Mon, 7 Feb 2022 21:42 UTC

On 07/02/2022 08:11, Mateusz Viste wrote:
> 2022-02-06 at 22:08 +0000, Vir Campestris wrote:
>> bool lets the compiler pick a type where the architecture can store 2
>> values easily.
>>
>> int_fast8_t is only convenient on machines that have hardware byte
>> support. OK, that's most of them, but by no means all.
>
> int_fast8_t is convenient on machines that have hardware support for
> anything that is at least 8 bits large. I imagine that on a machine
> like the one you describe (no bytes, words only) int_fast8_t would be a
> word.
>
... which means using 64 bits for each boolean. If you cared about space
you'd probably use a bitmask.

bool tells the compiler what you are going to put in it.

The compiler optimisation settings tell the compiler whether you care
about speed or size.

As I said originally it's entirely valid for the compiler to put a bunch
of bools into a bitmask (as long as you never ask for their address!)
but it can't do that if you've insisted that it store at least 8 bits.

Andy

Re: How to avoid an overflow during multiplication?

<sts7aj$ig3$1@gioia.aioe.org>

  copy mid

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

  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, 7 Feb 2022 23:43:31 +0100
Organization: . . .
Message-ID: <sts7aj$ig3$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>
<86pmojo7th.fsf@linuxsc.com>
<sslpp3$61s$2@gioia.aioe.org>
<86sfszlsfd.fsf@linuxsc.com>
<sthe7t$1cph$1@gioia.aioe.org>
<sthkum$5nu$2@dont-email.me>
<sthm4i$d2b$1@gioia.aioe.org>
<stpgso$op1$1@dont-email.me>
<stqk7g$go3$1@gioia.aioe.org>
<sts3p3$gpj$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="18947"; 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, 7 Feb 2022 22:43 UTC

2022-02-07 at 21:42 +0000, Vir Campestris wrote:
> > int_fast8_t is convenient on machines that have hardware support for
> > anything that is at least 8 bits large. I imagine that on a machine
> > like the one you describe (no bytes, words only) int_fast8_t would
> > be a word.
> >
> .. which means using 64 bits for each boolean. If you cared about
> space you'd probably use a bitmask.

If I cared about space, then I'd probably use a simple char, because a
bitmask might actually end up taking more space than using a single
byte. If we really are that much space-constrained, then it is
important to also account for all the extra shifting, ANDing and ORing
operations that the program will have to contain for handling the
bitmask each time a flag is accessed.

> bool tells the compiler what you are going to put in it.
>
> The compiler optimisation settings tell the compiler whether you care
> about speed or size.

That's delegation. And it's fine, but whatever the compiler chooses to
do is not guaranteed to be what I want... esp. in the extreme context
you suggest (ie. a program so space-constrained that one needs to count
every bit of memory).

> As I said originally it's entirely valid for the compiler to put a
> bunch of bools into a bitmask (as long as you never ask for their
> address!) but it can't do that if you've insisted that it store at
> least 8 bits.

Bitmasks are cool, but not for the reason you mentioned - at least not
from my point of view. I like bitmasks because I find them to be an
elegant and convenient way of passing many flags to a function with a
single argument and still having nice, self-explanatory names (while
not cluttering the function call with all the flags I am not passing).
Having the compiler store bools inside a bitmask is a debatable
feature... We do not get the advantage of function call clarity that a
bitmask provides, but do have its drawbacks (slower to access and more
code required).

Mateusz

Re: How to avoid an overflow during multiplication?

<ddmv7h9ij6mnea18ubop2kbt1u8msed1dl@4ax.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: dave_tho...@comcast.net
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sat, 14 May 2022 12:34:47 -0400
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <ddmv7h9ij6mnea18ubop2kbt1u8msed1dl@4ax.com>
References: <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> <86sfszlsfd.fsf@linuxsc.com> <sthe7t$1cph$1@gioia.aioe.org> <86ee4hlwrw.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="e34468f8686b457375b1858efe710eac";
logging-data="16781"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+e2vSUasFfjO0+AO+6Tde3AZg2M+7zjCg="
Cancel-Lock: sha1:60Glv9aR7znWpJdIsRy67hEVDKo=
X-Newsreader: Forte Agent 3.3/32.846
 by: dave_tho...@comcast.net - Sat, 14 May 2022 16:34 UTC

(Sorry for delay, I just found this somehow went in a file folder
instead of outbox)

On Fri, 04 Feb 2022 21:14:59 -0800, Tim Rentsch
<tr.17687@z991.linuxsc.com> wrote:

> Mateusz Viste <mateusz@xyz.invalid> writes:
> > so let me ask: what C99 feature do you use, that you wouldn't want
> > to loose?
....
> First there are several constructs that C89/C90 permits but are
> disallowed in C99:
....
> * 'return' statements need not give an expression in a
> function that returns a non-void type, and conversely
>
> I understand why K&R C (and later C89/C90) allowed these things.
....
Not conversely. return expr in void function was a constraint
violation in C89/90. (And impossible in K&R which had no void.)

Re: How to avoid an overflow during multiplication?

<t5oufa$e8k$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sat, 14 May 2022 12:04:07 -0700
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <t5oufa$e8k$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> <86pmojo7th.fsf@linuxsc.com>
<sslpp3$61s$2@gioia.aioe.org> <86sfszlsfd.fsf@linuxsc.com>
<sthe7t$1cph$1@gioia.aioe.org> <86ee4hlwrw.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 14 May 2022 19:04:11 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b49796332bb2943794a6d0916fefb199";
logging-data="14612"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184XGNaVenusYBCs4gAnqI6"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Cancel-Lock: sha1:SFjSyKWJOEXkWNOtRclYzTcYk9g=
In-Reply-To: <86ee4hlwrw.fsf@linuxsc.com>
Content-Language: en-US
 by: Andrey Tarasevich - Sat, 14 May 2022 19:04 UTC

On 2/4/2022 9:14 PM, Tim Rentsch wrote:
>
> First there are several constructs that C89/C90 permits but are
> disallowed in C99:
>
> * calls to functions not previously declared are implicitly
> declared (with nothing known about the parameter types, and
> as returning type 'int')

True.

> * declarations (especially functions) are allowed not to give
> a type specifier, in which case the type defaults to 'int'

With one remark: in C89/90 a declaration has to specify at least one
declaration-specifier, which is a storage-class-specifier,
type-specifier or a type-qualifier. Declarations that have none are
illegal in C89/90

/* File scope */
foo(); /* this is not a valid declaration */
const bar(); /* this is a valid declaration, implicit `int` */
static baz(); /* this is a valid declaration, implicit `int` */

The only exception from this rule is function *definitions*, which are
governed by a separate branch of grammar

qux() {} /* this is a valid definition, implicit `int` */

> * 'return' statements need not give an expression in a
> function that returns a non-void type, and conversely

True, but not the "conversely" part. Supplying an expression to a
`return` statement in a `void` function is a constraint violation.

>
> Number 4: variadic macros. Compare this fragment
>
> case 1: case 2: case 3: case 4:
> case 5: case 6: case 7: case 8: case 9:
>
> with this fragment
>
> cases(1,2,3,4,5,6,7,8,9):

Well, the latter is a constraint violation in all versions of standard
C. Comma operator is not allowed in constant expressions. It is C++ that
lifted that restriction, but in C it still stands.

--
Best regards,
Andrey

Re: How to avoid an overflow during multiplication?

<t5ov40$j3k$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sat, 14 May 2022 12:15:09 -0700
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <t5ov40$j3k$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> <86pmojo7th.fsf@linuxsc.com>
<sslpp3$61s$2@gioia.aioe.org> <86sfszlsfd.fsf@linuxsc.com>
<sthe7t$1cph$1@gioia.aioe.org> <86ee4hlwrw.fsf@linuxsc.com>
<t5oufa$e8k$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 14 May 2022 19:15:12 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b49796332bb2943794a6d0916fefb199";
logging-data="19572"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19+tBQbr1goydeLNZtyZnAS"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Cancel-Lock: sha1:1ipBXme45WEOklwon1asNEHojzU=
In-Reply-To: <t5oufa$e8k$1@dont-email.me>
Content-Language: en-US
 by: Andrey Tarasevich - Sat, 14 May 2022 19:15 UTC

On 5/14/2022 12:04 PM, Andrey Tarasevich wrote:
>> Number 4: variadic macros.  Compare this fragment
>>
>>      case 1: case 2: case 3: case 4:
>>      case 5: case 6: case 7: case 8: case 9:
>>
>> with this fragment
>>
>>      cases(1,2,3,4,5,6,7,8,9):
>
> Well, the latter is a constraint violation in all versions of standard
> C. Comma operator is not allowed in constant expressions. It is C++ that
> lifted that restriction, but in C it still stands.

Oh... My mistake. Apparently I misunderstood what was being said. You
mean that `cases` is a macro that unfolds into a bunch of separate
`case` labels. Got it. No problems then.

I missed the fact that it is spelled as `cases`. I misread it as

case (1,2,3,4,5,6,7,8,9):

which would be legal in modern C++, but not in C.

--
Best regards,
Andrey

Re: How to avoid an overflow during multiplication?

<861qwu5162.fsf@linuxsc.com>

  copy mid

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

  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, 15 May 2022 07:19:01 -0700
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <861qwu5162.fsf@linuxsc.com>
References: <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> <86sfszlsfd.fsf@linuxsc.com> <sthe7t$1cph$1@gioia.aioe.org> <86ee4hlwrw.fsf@linuxsc.com> <ddmv7h9ij6mnea18ubop2kbt1u8msed1dl@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="90fae27f8c3ebf4ec54f5551ea17134b";
logging-data="23066"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ygr97dfYaY0+hJ8LoMvRj3bO6Y4sihYU="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:XkH4ozjJl04BvdRy7qonVCm5bJY=
sha1:D7DT++8zhyoswkKoW4CKCkYxeTQ=
 by: Tim Rentsch - Sun, 15 May 2022 14:19 UTC

dave_thompson_2@comcast.net writes:

> (Sorry for delay, I just found this somehow went in a file folder
> instead of outbox)
>
> On Fri, 04 Feb 2022 21:14:59 -0800, Tim Rentsch
> <tr.17687@z991.linuxsc.com> wrote:
>
>> Mateusz Viste <mateusz@xyz.invalid> writes:
>>
>>> so let me ask: what C99 feature do you use, that you wouldn't want
>>> to loose?
>
> ...
>
>> First there are several constructs that C89/C90 permits but are
>> disallowed in C99:
>
> ...
>
>> * 'return' statements need not give an expression in a
>> function that returns a non-void type, and conversely
>>
>> I understand why K&R C (and later C89/C90) allowed these things.
>
> ...
> Not conversely. return expr in void function was a constraint
> violation in C89/90. (And impossible in K&R which had no void.)

Thank you for the follow-up (and no worries about the delay).

To the best of my knowledge all of the following are true
statements.

K&R C did not have a void type (although some pre-standard C
compilers may have had support for void).

In both the ANSI C standard (C89) and the first ISO C standard
(C90), a return statement with an expression is a constraint
violation if it appears in a function whose return type is void
(although some pre-standard C compilers may not have observed
this rule).

K&R C, C89, and C90 all allow things like this:

int
f(){
...
return;
}

g(){
...
return 0;
}

In the ISO C99 standard, paragraph 5 in the Foreword says (in
part) the following:

This second edition cancels and replaces the first edition,
ISO/IEC 9899:1990, as amended and corrected by ISO/IEC
9899/COR1:1994, ISO/IEC 9899/AMD1:1995, and ISO/IEC
9899/COR2:1996. Major changes from the previous edition
include:

[...]

-- return without expression not permitted in function
that returns a value (and vice versa)

I hope these observations clarify my earlier comment.

Re: How to avoid an overflow during multiplication?

<86wnem3mbm.fsf@linuxsc.com>

  copy mid

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

  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, 15 May 2022 07:25:01 -0700
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <86wnem3mbm.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> <86sfszlsfd.fsf@linuxsc.com> <sthe7t$1cph$1@gioia.aioe.org> <86ee4hlwrw.fsf@linuxsc.com> <t5oufa$e8k$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="90fae27f8c3ebf4ec54f5551ea17134b";
logging-data="23066"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+VwqixSPA1TpYdzAS09jMQ2X2Yn3bcnpo="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:QI9UlaLbH2CaubIe8F8uqtACTXo=
sha1:4GmfksjApqZs+0segF3f7ioh68w=
 by: Tim Rentsch - Sun, 15 May 2022 14:25 UTC

Andrey Tarasevich <andreytarasevich@hotmail.com> writes:

> On 2/4/2022 9:14 PM, Tim Rentsch wrote:
>
>> First there are several constructs that C89/C90 permits but are
>> disallowed in C99:
>>
>> * calls to functions not previously declared are implicitly
>> declared (with nothing known about the parameter types, and
>> as returning type 'int')
>
> True.
>
>> * declarations (especially functions) are allowed not to give
>> a type specifier, in which case the type defaults to 'int'
>
> With one remark: in C89/90 a declaration has to specify at least
> one declaration-specifier, [...]

Yes, the statement is only about type specifiers, not other
declaration specifiers.

>> * 'return' statements need not give an expression in a
>> function that returns a non-void type, and conversely
>
> True, but not the "conversely" part. Supplying an expression to a
> return` statement in a `void` function is a constraint violation.

A post from Dave Thompson gave this same observation, and I have
just now responded to his posting.

Pages:12345678
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor