Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

He's dead, Jim. -- McCoy, "The Devil in the Dark", stardate 3196.1


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

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

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

<stm4co$8r8$1@dont-email.me>

  copy mid

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

  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: Sat, 5 Feb 2022 15:16:40 +0000
Organization: A noiseless patient Spider
Lines: 81
Message-ID: <stm4co$8r8$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>
<stip0g$1aii$1@gioia.aioe.org> <stitqj$23u$1@dont-email.me>
<stjvbo$dmc$1@dont-email.me> <stltoc$u8l$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 5 Feb 2022 15:16:40 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7de8a5e388e6a550646592aa2c3845fb";
logging-data="9064"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18nOReMFitFZPm+PsXMLHhqQ3yAUB4/Ylk="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:RaSD8eQlUC5VBYKt8N3sSDe6aws=
In-Reply-To: <stltoc$u8l$1@dont-email.me>
 by: Bart - Sat, 5 Feb 2022 15:16 UTC

On 05/02/2022 13:23, David Brown wrote:
> On 04/02/2022 20:38, Bart wrote:
>> On 04/02/2022 10:06, David Brown wrote:
>
>>> Secondly, there are technical differences.  The conversion of an integer
>>> "x" to a _Bool "b" is effectively "b = !!x;".  You are guaranteed that
>>> "b" is either 0 or 1 - and the compiler can use that knowledge for
>>> optimisation (as can the programmer).  This can mean some operations
>>> (such as conversion from an integer) may be less efficient, but other
>>> operations (such as logical operations) are more efficient.  Overall, it
>>> is usually a win.
>>
>> You're never really quite sure what's happening with _Bool.
>>
>> There's little control over its size. And in A program like this:
>>
>>     union {
>>         _Bool a;
>>         unsigned char b;
>>     } x;
>>
>>     x.b=0x55;
>>     printf("A= %X\n", x.a);
>>     printf("B= %X\n", x.b);
>>
>
> <snip>
>
>> You can probably claim this is due to UB or whatever, but the fact
>> remains that using regular int types, the results will be consistent and
>> predictable across all compilers. It /is/ possible for the byte value
>> that usually represents a bool type to be set something that is neither
>> true (1) or false (0).
>>
>
> It /is/ undefined behaviour. (6.2.6.1p5 covers it, though I doubt if
> you care.) It is also common sense. A _Bool contains either 0 or 1 -
> any other value is invalid and can't be achieved without extraordinary
> effort designed purely to make bad code.
>
> Yes, you know /exactly/ what is happening with _Bool - write sane code,
> and you get the results you expect. Write code with clear and
> intentional errors with the sole intention of getting inconsistent
> results, and you get exactly what you expect.

My point is exactly that you don't know what's going on, if not because
it's UB, it's because it's implementation defined or for some other
weird reason. Take this:

_Bool a=0;

for (int i=0; i<10; ++i){
printf("%d ",a);
++a;
}

What will be the output? For ++a, it's:

0 1 1 1 1 1 ...

But for --a it's:

0 1 0 1 0 1 ...

(With MSVC, it's all zeros. With 2 lesser compilers, it's 0 -1 -2 -3 ...)

Try this:

a = 1;
++a;
--a;

Normally ++ and -- cancel out, but here a ends up as 0. But reverse the
increments, and now the result is 1.

_Bool has special semantics compared with int, yet the language still
allows you to do all things associated with int.

What is type result type of !!? It is int, not _Bool. _Bool is a
half-hearted attempt at a proper Boolean type. I prefer to use 0 and 1
values of int, or 0 and non-zero, then I know exactly where I'm at.

Re: How to avoid an overflow during multiplication?

<stm8i0$422$1@dont-email.me>

  copy mid

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

  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, 5 Feb 2022 17:27:43 +0100
Organization: A noiseless patient Spider
Lines: 125
Message-ID: <stm8i0$422$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>
<stip0g$1aii$1@gioia.aioe.org> <stitqj$23u$1@dont-email.me>
<stjvbo$dmc$1@dont-email.me> <stltoc$u8l$1@dont-email.me>
<stm4co$8r8$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 5 Feb 2022 16:27:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="52c46bbcd0ca92139da95b7ca8139772";
logging-data="4162"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8pSNh/ertPNH0XsquKbsgCrZgNcjS8g0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:EzQS8i++kFcGly2TfC2hp8XugNU=
In-Reply-To: <stm4co$8r8$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Sat, 5 Feb 2022 16:27 UTC

On 05/02/2022 16:16, Bart wrote:
> On 05/02/2022 13:23, David Brown wrote:
>> On 04/02/2022 20:38, Bart wrote:
>>> On 04/02/2022 10:06, David Brown wrote:
>>
>>>> Secondly, there are technical differences.  The conversion of an
>>>> integer
>>>> "x" to a _Bool "b" is effectively "b = !!x;".  You are guaranteed that
>>>> "b" is either 0 or 1 - and the compiler can use that knowledge for
>>>> optimisation (as can the programmer).  This can mean some operations
>>>> (such as conversion from an integer) may be less efficient, but other
>>>> operations (such as logical operations) are more efficient. 
>>>> Overall, it
>>>> is usually a win.
>>>
>>> You're never really quite sure what's happening with _Bool.
>>>
>>> There's little control over its size. And in A program like this:
>>>
>>>      union {
>>>          _Bool a;
>>>          unsigned char b;
>>>      } x;
>>>
>>>      x.b=0x55;
>>>      printf("A= %X\n", x.a);
>>>      printf("B= %X\n", x.b);
>>>
>>
>> <snip>
>>
>>> You can probably claim this is due to UB or whatever, but the fact
>>> remains that using regular int types, the results will be consistent and
>>> predictable across all compilers. It /is/ possible for the byte value
>>> that usually represents a bool type to be set something that is neither
>>> true (1) or false (0).
>>>
>>
>> It /is/ undefined behaviour.  (6.2.6.1p5 covers it, though I doubt if
>> you care.)  It is also common sense.  A _Bool contains either 0 or 1 -
>> any other value is invalid and can't be achieved without extraordinary
>> effort designed purely to make bad code.
>>
>> Yes, you know /exactly/ what is happening with _Bool - write sane code,
>> and you get the results you expect.  Write code with clear and
>> intentional errors with the sole intention of getting inconsistent
>> results, and you get exactly what you expect.
>
> My point is exactly that you don't know what's going on, if not because
> it's UB, it's because it's implementation defined or for some other
> weird reason. Take this:
>
>     _Bool a=0;
>
>     for (int i=0; i<10; ++i){
>         printf("%d  ",a);
>         ++a;
>     }
>
> What will be the output? For ++a, it's:
>
>   0 1 1 1 1 1 ...

++a means (a += 1), which in turn means (a = a + 1). The boolean is
converted to an int (either 0 or 1), and 1 is added giving either 1 or
2. Conversion back to _Bool is on the basis of comparison to 0 - since
neither 1 nor 2 compares equal to 0, the result of "++a" will always
leave "a" as "true".

>
> But for --a it's:
>
>   0 1 0 1 0 1 ...

Similar reasoning - if "a" is currently "true", then after "--a" it is
left as "false". If "a" is currently "false", then "a = a - 1" will
give "a = -1", and thus set "a" to "true" (1).

It's not hard, not UB, not unexpected. (It is also almost certainly not
found in real code, which is why compilers like gcc with "-Wall" will
warn you that it's probably a mistake in your code. And in C++, it is
not allowed at all.)

>
> (With MSVC, it's all zeros. With 2 lesser compilers, it's 0 -1 -2 -3 ...)

MSVC is primarily a C++ compiler, not a C compiler. I don't have access
to it other than via <https://godbolt.org>, and there it is only C++.
But almost certainly, you have made an error - it seems far more likely
than supposing MS failed to correctly implement _Bool in C.

For the "lesser compilers", you are clearly using an "int", not a "_Bool".

>
> Try this:
>
>     a = 1;
>     ++a;
>     --a;
>
> Normally ++ and -- cancel out, but here a ends up as 0. But reverse the
> increments, and now the result is 1.

"_Bool" is not "int". Why would you think it acts like it?

>
> _Bool has special semantics compared with int, yet the language still
> allows you to do all things associated with int.
>
> What is type result type of !!? It is int, not _Bool. _Bool is a
> half-hearted attempt at a proper Boolean type. I prefer to use 0 and 1
> values of int, or 0 and non-zero, then I know exactly where I'm at.

The logical and relational operators in C evaluate to "int", values 0 or
1, preceding the introduction of _Bool to the language.

The fact that you personally get confused about _Bool and don't
understand what it is and how it is defined, does not mean that it is
unclear, confusing, imprecise, or that anyone else fails to comprehend it.

However, now you know the rules that apply even when doing something as
deliberately unrealistic and pointless as incrementing or decrementing a
boolean variable. So you can no longer claim that you don't understand
it, or are not sure what is going on, and can now happily make use of
this extremely useful type.

Re: How to avoid an overflow during multiplication?

<stm9ci$9k6$1@dont-email.me>

  copy mid

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

  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: Sat, 5 Feb 2022 16:41:54 +0000
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <stm9ci$9k6$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>
<stip0g$1aii$1@gioia.aioe.org> <stitqj$23u$1@dont-email.me>
<stjvbo$dmc$1@dont-email.me> <stltoc$u8l$1@dont-email.me>
<stm4co$8r8$1@dont-email.me> <stm8i0$422$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 5 Feb 2022 16:41:54 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7de8a5e388e6a550646592aa2c3845fb";
logging-data="9862"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1854XsXbUDor4yuBEYv1M9OkPuQQiG3KuE="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:cOHoMqrqowbIdKxg4jtccjKtgOc=
In-Reply-To: <stm8i0$422$1@dont-email.me>
 by: Bart - Sat, 5 Feb 2022 16:41 UTC

On 05/02/2022 16:27, David Brown wrote:
> On 05/02/2022 16:16, Bart wrote:

> The fact that you personally get confused about _Bool and don't
> understand what it is and how it is defined, does not mean that it is
> unclear, confusing, imprecise, or that anyone else fails to comprehend it.
>
> However, now you know the rules that apply even when doing something as
> deliberately unrealistic and pointless as incrementing or decrementing a
> boolean variable. So you can no longer claim that you don't understand
> it, or are not sure what is going on, and can now happily make use of
> this extremely useful type.

OK, so I see _Bool used in APIs which I might want to call via an FFI.

Which more universal type is most likely to correspond to it? What are
the actual values I can expect to see across all bits? What assumptions
can I make?

I'd quite like to know those answers when coding in C too!

Re: How to avoid an overflow during multiplication?

<f2c562fa-cf23-4cb3-90b1-d18b2711d561n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ae9:df85:: with SMTP id t127mr2389148qkf.744.1644081308970;
Sat, 05 Feb 2022 09:15:08 -0800 (PST)
X-Received: by 2002:a05:620a:c44:: with SMTP id u4mr2455363qki.319.1644081308807;
Sat, 05 Feb 2022 09:15:08 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 5 Feb 2022 09:15:08 -0800 (PST)
In-Reply-To: <stlt2u$q62$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:2839:d352:7851:e164;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:2839:d352:7851:e164
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>
<stip0g$1aii$1@gioia.aioe.org> <stitqj$23u$1@dont-email.me>
<46fd23b2-d691-4742-b387-f66d071463a7n@googlegroups.com> <stjd4t$722$1@dont-email.me>
<stjele$1hsd$1@gioia.aioe.org> <stlt2u$q62$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f2c562fa-cf23-4cb3-90b1-d18b2711d561n@googlegroups.com>
Subject: Re: How to avoid an overflow during multiplication?
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Sat, 05 Feb 2022 17:15:08 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 52
 by: Malcolm McLean - Sat, 5 Feb 2022 17:15 UTC

On Saturday, 5 February 2022 at 13:12:32 UTC, David Brown wrote:
> On 04/02/2022 15:53, Mateusz Viste wrote:
> > 2022-02-04 at 15:27 +0100, David Brown wrote:
> >> That is a completely separate issue, and nothing to do with the
> >> question, which was "what advantages are there to using _Bool over an
> >> plain integer type?".
> >
> > I think that in a vicious way, it is not separate.
> >
> >> Yes, it's hard to see what
> >> SetSpnEdit(height_spn, height, true, false, false);
> >>
> >> is doing. But you don't make anything better by writing
> >> SetSpnEdit(height_spn, height, 1, 0, 0);
> >
> > If I would be a user of _Bool, I'd be very tempted to use the first form
> > (and end up with a hardly readable line).
> I think you need to work on your temptation issues. When a language
> supports a feature, you are not /required/ to use it just because it is
> there. There are perhaps a dozen different ways to make the call to
> SetSpnEdit clearer and safer - none of them are in any way broken by the
> existence of "_Bool".
> > I guess it's a vicious side effect of the human mind - "if I have a
> > hammer, then everything looks like nails". :-)
> >
> You seem to be limiting yourself severely as a programmer. How you code
> is of course up to you, but please do not assume all programmers are
> going to see things that way.
>
> And your analogy is all wrong. You are claiming that because you only
> have a hammer (int), you are better equipped to invent a spanner when
> you need it than people who also have access to a screwdriver (_Bool).
>
>
> There is an argument to be made that the power of a programming language
> comes from what it stops you from doing just as much as from what it
> allows you to do, and that more features and possibilities allows for
> more misuse as well as more good usage.
>
Yes. In C you can't refer to anything outside the source file, unless you
import it via a header or declare it "extern" in that source file. That's a good
restriction that keeps code modular. You can't use non-Latin identifiers,
which is another good rule, because most educated people can read Latin
script, but most programmers can't read most of the other alphabets in
existence.
You could enforce a rule that a function cannot take more than one boolean
parameter. That would prevent a castastophe such as SetSpnEdit. But
language standards committees are reluctant to pass stylistic rules like
that.
Goto is considered harmful. So some languages disallowed it. However it's
often had to be put back in, because automatic code generators which are
banned from using goto are harder to write. That's an example of how improving
a language by removing abiliites can be double-edged.

Re: How to avoid an overflow during multiplication?

<3b6f2718-aff3-4d04-b44b-fb65ebcdef32n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:192:: with SMTP id s18mr3193374qtw.43.1644082701946;
Sat, 05 Feb 2022 09:38:21 -0800 (PST)
X-Received: by 2002:a05:620a:25cc:: with SMTP id y12mr2581709qko.94.1644082701733;
Sat, 05 Feb 2022 09:38:21 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 5 Feb 2022 09:38:21 -0800 (PST)
In-Reply-To: <stm4co$8r8$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=108.48.119.9; posting-account=Ix1u_AoAAAAILVQeRkP2ENwli-Uv6vO8
NNTP-Posting-Host: 108.48.119.9
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>
<stip0g$1aii$1@gioia.aioe.org> <stitqj$23u$1@dont-email.me>
<stjvbo$dmc$1@dont-email.me> <stltoc$u8l$1@dont-email.me> <stm4co$8r8$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3b6f2718-aff3-4d04-b44b-fb65ebcdef32n@googlegroups.com>
Subject: Re: How to avoid an overflow during multiplication?
From: jameskuy...@alumni.caltech.edu (james...@alumni.caltech.edu)
Injection-Date: Sat, 05 Feb 2022 17:38:21 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 50
 by: james...@alumni.calt - Sat, 5 Feb 2022 17:38 UTC

On Saturday, February 5, 2022 at 10:17:11 AM UTC-5, Bart wrote:
....
> My point is exactly that you don't know what's going on, if not because
> it's UB, it's because it's implementation defined or for some other
> weird reason. Take this:
>
> _Bool a=0;
>
> for (int i=0; i<10; ++i){
> printf("%d ",a);
> ++a;
> }
>
> What will be the output? For ++a, it's:
>
> 0 1 1 1 1 1 ...
>
> But for --a it's:
>
> 0 1 0 1 0 1 ...
>
> (With MSVC, it's all zeros. With 2 lesser compilers, it's 0 -1 -2 -3 ...)
>
> Try this:
>
> a = 1;
> ++a;
> --a;
>
> Normally ++ and -- cancel out, but here a ends up as 0. But reverse the
> increments, and now the result is 1.
>
> _Bool has special semantics compared with int, yet the language still
> allows you to do all things associated with int.
>
> What is type result type of !!? It is int, not _Bool. _Bool is a
> half-hearted attempt at a proper Boolean type. I prefer to use 0 and 1
> values of int, or 0 and non-zero, then I know exactly where I'm at.

The rules are really quite simple: _Bool expressions get promoted to int values of either 0 or 1, depending upon whether the _Bool value is false or true. During the evaluation of all expressions, those values behave the same as any other int with a value of 0 or 1. On conversion to _Bool, values that compare equal to zero get converted to false, all other values convert to true. Everything you've observed is explained by those simple rules, except for the behavior you've described for "2 lesser compilers", which is non-conforming. You can't blame C for the behavior of compilers that fail to to conform to its rules.

Re: How to avoid an overflow during multiplication?

<b3308ea0-82c1-4615-b058-5a6ed18772e2n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:54c:: with SMTP id m12mr3241191qtx.300.1644083433148;
Sat, 05 Feb 2022 09:50:33 -0800 (PST)
X-Received: by 2002:ac8:5c86:: with SMTP id r6mr3261309qta.20.1644083432995;
Sat, 05 Feb 2022 09:50:32 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 5 Feb 2022 09:50:32 -0800 (PST)
In-Reply-To: <stjvbo$dmc$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=108.48.119.9; posting-account=Ix1u_AoAAAAILVQeRkP2ENwli-Uv6vO8
NNTP-Posting-Host: 108.48.119.9
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>
<stip0g$1aii$1@gioia.aioe.org> <stitqj$23u$1@dont-email.me> <stjvbo$dmc$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b3308ea0-82c1-4615-b058-5a6ed18772e2n@googlegroups.com>
Subject: Re: How to avoid an overflow during multiplication?
From: jameskuy...@alumni.caltech.edu (james...@alumni.caltech.edu)
Injection-Date: Sat, 05 Feb 2022 17:50:33 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 48
 by: james...@alumni.calt - Sat, 5 Feb 2022 17:50 UTC

On Friday, February 4, 2022 at 2:39:14 PM UTC-5, Bart wrote:
....
> union {
> _Bool a;
> unsigned char b;
> } x;
>
> x.b=0x55;
> printf("A= %X\n", x.a);
> printf("B= %X\n", x.b);
>
> if (x.a == true) puts("A is True");
> if (x.a == false) puts("A is False");
> if (x.a != true && x.a != false) puts("A is neither True nor False");
>
> different compilers show different results, including this from gcc -O0:
>
> A= 55
> B= 55
> A is True
> A is False
> A is neither True nor False
>
> MSVC shows this:
>
> A= 55
> B= 55
> A is neither True nor False
>
> while Clang, and gcc -O3, displays:
>
> A= 1
> B= 55
> A is True
>
> You can probably claim this is due to UB or whatever, but the fact
> remains that using regular int types, the results will be consistent and
> predictable across all compilers.

Could you name a single type other than char, unsigned char, or signed
char, that could be used to replace _Bool in that code, which would result
in your code having consistent results on all implementations?
Type punning between incompatible types almost always has, at best,
implementation-defined results. The only reason that signed char would
work is this particular case is that the signed and unsigned versions of char
are mandated to have the same representation for positive values of signed
char, making them semi-compatible. Even that would disappear if your code had
used a value greater than SCHAR_MAX.

Re: How to avoid an overflow during multiplication?

<stmdqj$6sj$1@dont-email.me>

  copy mid

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

  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: Sat, 5 Feb 2022 17:57:38 +0000
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <stmdqj$6sj$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>
<stip0g$1aii$1@gioia.aioe.org> <stitqj$23u$1@dont-email.me>
<stjvbo$dmc$1@dont-email.me> <stltoc$u8l$1@dont-email.me>
<stm4co$8r8$1@dont-email.me>
<3b6f2718-aff3-4d04-b44b-fb65ebcdef32n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 5 Feb 2022 17:57:39 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7de8a5e388e6a550646592aa2c3845fb";
logging-data="7059"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+zqkveYdmbUw9MrFHPsKbnJX8rk1hYYts="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:UV32DOmA3fDn38gU3Ib/z6mrUls=
In-Reply-To: <3b6f2718-aff3-4d04-b44b-fb65ebcdef32n@googlegroups.com>
 by: Bart - Sat, 5 Feb 2022 17:57 UTC

On 05/02/2022 17:38, james...@alumni.caltech.edu wrote:
> On Saturday, February 5, 2022 at 10:17:11 AM UTC-5, Bart wrote:
> ...
>> My point is exactly that you don't know what's going on, if not because
>> it's UB, it's because it's implementation defined or for some other
>> weird reason. Take this:
>>
>> _Bool a=0;
>>
>> for (int i=0; i<10; ++i){
>> printf("%d ",a);
>> ++a;
>> }
>>
>> What will be the output? For ++a, it's:
>>
>> 0 1 1 1 1 1 ...
>>
>> But for --a it's:
>>
>> 0 1 0 1 0 1 ...
>>
>> (With MSVC, it's all zeros. With 2 lesser compilers, it's 0 -1 -2 -3 ...)
>>
>> Try this:
>>
>> a = 1;
>> ++a;
>> --a;
>>
>> Normally ++ and -- cancel out, but here a ends up as 0. But reverse the
>> increments, and now the result is 1.
>>
>> _Bool has special semantics compared with int, yet the language still
>> allows you to do all things associated with int.
>>
>> What is type result type of !!? It is int, not _Bool. _Bool is a
>> half-hearted attempt at a proper Boolean type. I prefer to use 0 and 1
>> values of int, or 0 and non-zero, then I know exactly where I'm at.
>
> The rules are really quite simple: _Bool expressions get promoted to int values of either 0 or 1, depending upon whether the _Bool value is false or true. During the evaluation of all expressions, those values behave the same as any other int with a value of 0 or 1. On conversion to _Bool, values that compare equal to zero get converted to false, all other values convert to true. Everything you've observed is explained by those simple rules,

It doesn't explain the behaviour of MSVC [19.28.29337 for x64], which
outputs all zeros. Maybe another non-conforming one?

> except for the behavior you've described for "2 lesser compilers", which is non-conforming. You can't blame C for the behavior of compilers that fail to to conform to its rules.

Re: How to avoid an overflow during multiplication?

<stmegf$bie$1@dont-email.me>

  copy mid

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

  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: Sat, 5 Feb 2022 18:09:20 +0000
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <stmegf$bie$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>
<stip0g$1aii$1@gioia.aioe.org> <stitqj$23u$1@dont-email.me>
<stjvbo$dmc$1@dont-email.me>
<b3308ea0-82c1-4615-b058-5a6ed18772e2n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 5 Feb 2022 18:09:19 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7de8a5e388e6a550646592aa2c3845fb";
logging-data="11854"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+d/L5Gm/0MmeOJ/ZCcP8/+F5glnSw5B6U="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:FS2JvLhkDt0zwo8fjULfrW61nf4=
In-Reply-To: <b3308ea0-82c1-4615-b058-5a6ed18772e2n@googlegroups.com>
 by: Bart - Sat, 5 Feb 2022 18:09 UTC

On 05/02/2022 17:50, james...@alumni.caltech.edu wrote:
> On Friday, February 4, 2022 at 2:39:14 PM UTC-5, Bart wrote:
> ...
>> union {
>> _Bool a;
>> unsigned char b;
>> } x;
>>
>> x.b=0x55;
>> printf("A= %X\n", x.a);
>> printf("B= %X\n", x.b);
>>
>> if (x.a == true) puts("A is True");
>> if (x.a == false) puts("A is False");
>> if (x.a != true && x.a != false) puts("A is neither True nor False");
>>
>> different compilers show different results, including this from gcc -O0:
>>
>> A= 55
>> B= 55
>> A is True
>> A is False
>> A is neither True nor False
>>
>> MSVC shows this:
>>
>> A= 55
>> B= 55
>> A is neither True nor False
>>
>> while Clang, and gcc -O3, displays:
>>
>> A= 1
>> B= 55
>> A is True
>>
>> You can probably claim this is due to UB or whatever, but the fact
>> remains that using regular int types, the results will be consistent and
>> predictable across all compilers.
>
>
> Could you name a single type other than char, unsigned char, or signed
> char,

Why other than those types? They are the only choices if I wanted an
8-bit boolean representation. With 'char' used in place of _Bool, then
all compilers I tried have the same output, that of MSVC above, with
both members having values of 0x55, and .a being neither true/1 nor
false/0, which it isn't.

gcc had the most bizarre behaviour where .a was simultaneously both true
and not true, and both false and not false!

Using a wider type for .a than .b would give more unpredictable results,
but for reasons that are obvious across all compilers: the top bits of
..a will be garbage.

Re: How to avoid an overflow during multiplication?

<mmzLJ.10298$r6p7.6237@fx41.iad>

  copy mid

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

  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!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx41.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.1
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> <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>
<stip0g$1aii$1@gioia.aioe.org> <stitqj$23u$1@dont-email.me>
<stjvbo$dmc$1@dont-email.me> <stltoc$u8l$1@dont-email.me>
<stm4co$8r8$1@dont-email.me>
<3b6f2718-aff3-4d04-b44b-fb65ebcdef32n@googlegroups.com>
<stmdqj$6sj$1@dont-email.me>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <stmdqj$6sj$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 9
Message-ID: <mmzLJ.10298$r6p7.6237@fx41.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, 5 Feb 2022 13:29:38 -0500
X-Received-Bytes: 2090
 by: Richard Damon - Sat, 5 Feb 2022 18:29 UTC

On 2/5/22 12:57 PM, Bart wrote:
>
> It doesn't explain the behaviour of MSVC [19.28.29337 for x64], which
> outputs all zeros. Maybe another non-conforming one?

Could the code have been compiled as C++, it uses different rules.

If I remember right, in C++ if x is a bool, then x-- is defined to set x
false and return the previous value of x, a test and clear instruction.

Re: How to avoid an overflow during multiplication?

<stmglu$pn4$1@dont-email.me>

  copy mid

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

  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, 5 Feb 2022 13:46:21 -0500
Organization: A noiseless patient Spider
Lines: 85
Message-ID: <stmglu$pn4$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>
<stlk7a$1gp0$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 5 Feb 2022 18:46:22 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3d2b33619245bac830ff75ea2c47e9cd";
logging-data="26340"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ufBCNUHfA8jM82pYa5KzsL5K8ldqPIbg="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:Y8jzqU+sTdEzS4hg4v7H9pmOtA8=
In-Reply-To: <stlk7a$1gp0$1@gioia.aioe.org>
Content-Language: en-US
 by: James Kuyper - Sat, 5 Feb 2022 18:46 UTC

On 2/5/22 05:40, Mateusz Viste wrote:
> 2022-02-04 at 21:14 -0800, Tim Rentsch wrote:
....
>> Number 9: array parameters may have 'static' and 'const' etc.
>> Normally I use array notation (eg, 'int x[]') for parameters
>> that are treated as arrays rather than as pointers to single
>> objects. This feature allows length and qualifier information to
>> be added to the pointer parameter while still retaining array
>> notation in the parameter declaration.
>
> I am not sure I understand this one (and I also never use array
> notation in function parameters). Are you referring to such construct?
>
> void pupa(const char s[]) {
> printf("%c", s[0]);
> }
>
> Apparently this passes without warnings in both c89 and c99 modes of
> clang and gcc. But I probably misunderstood you.

He's referring to two separate features that were introduced in C99. In
all versions of standard C, all three of the following declarations have
exactly the same meaning:

void func(int []);
void func(int [25536]);
void func(int *);

This only applies to the leading dimension of pointers that are declared
as if they were arrays.

And the same is true of the corresponding K&R style definitions:
void func(a)
int a[];
{ }

void func(a)
int a[25536];
{ }

void func(a)
int *a;
{ }

You can debate the desirability of this feature, but it goes all the way
back to K&R C, and there's lots of code written using each of the three
different ways a pointer parameter can be declared.

In C99, the committee added the feature that you could put one or more
qualifiers (const, volatile, or restrict) into the first dimension of a
pointer parameter declared as if it was an array, and the effect would
be the same as if the qualifier was used in the appropriate location in
an ordinary pointer declaration:

int qualified(int array[const]);

means exactly the same thing as

int qualified(const int *array);

In C2011, _Atomic was added to the list of qualifiers.

The other feature is that you can declare a function parameter as follows:

double limited(float [static 36]);

"If the keyword static also appears within the [ and ] of the array type
derivation, then for each call to the function, the value of the
corresponding actual argument shall provide access to the first element
of an array with at least as many elements as specified by the size
expression." (7.5.3p7).

Violating this "shall" has undefined behavior (4p2), which doesn't sound
like much of an advantage. However, that also allows implementations to
warn you with a diagnostic, if they can determine that your code might
violate that requirement. If they can determine that it will
unconditionally violate that requirement, they can even reject the
program at compile time. It's that non-mandatory diagnostic that I
consider valuable. It cannot, unfortunately, be made mandatory, because
in many cases it's difficult, and often even impossible, to determine at
compile time whether a piece of code will violate that requirement. But
when it can be determined, I consider that a very valuable warning. YMMV.

Re: How to avoid an overflow during multiplication?

<stmt35$o14$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!W0ff0SLXbzIYQIMPtukEfg.user.46.165.242.75.POSTED!not-for-mail
From: inva...@add.invalid (Manfred)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sat, 5 Feb 2022 23:18:12 +0100
Organization: Aioe.org NNTP Server
Message-ID: <stmt35$o14$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> <sti5s0$dtj$1@dont-email.me>
<stip0g$1aii$1@gioia.aioe.org> <stitqj$23u$1@dont-email.me>
<stjvbo$dmc$1@dont-email.me> <stltoc$u8l$1@dont-email.me>
<stm4co$8r8$1@dont-email.me> <stm8i0$422$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="24612"; posting-host="W0ff0SLXbzIYQIMPtukEfg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:68.0) Gecko/20100101
Thunderbird/68.5.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Manfred - Sat, 5 Feb 2022 22:18 UTC

On 2/5/22 5:27 PM, David Brown wrote:
> On 05/02/2022 16:16, Bart wrote:
>> On 05/02/2022 13:23, David Brown wrote:
>>> On 04/02/2022 20:38, Bart wrote:
>>>> On 04/02/2022 10:06, David Brown wrote:
>>>
>>>>> Secondly, there are technical differences.  The conversion of an
>>>>> integer
>>>>> "x" to a _Bool "b" is effectively "b = !!x;".  You are guaranteed that
>>>>> "b" is either 0 or 1 - and the compiler can use that knowledge for
>>>>> optimisation (as can the programmer).  This can mean some operations
>>>>> (such as conversion from an integer) may be less efficient, but other
>>>>> operations (such as logical operations) are more efficient.
>>>>> Overall, it
>>>>> is usually a win.
>>>>
>>>> You're never really quite sure what's happening with _Bool.
>>>>
>>>> There's little control over its size. And in A program like this:
>>>>
>>>>      union {
>>>>          _Bool a;
>>>>          unsigned char b;
>>>>      } x;
>>>>
>>>>      x.b=0x55;
>>>>      printf("A= %X\n", x.a);
>>>>      printf("B= %X\n", x.b);
>>>>
>>>
>>> <snip>
>>>
>>>> You can probably claim this is due to UB or whatever, but the fact
>>>> remains that using regular int types, the results will be consistent and
>>>> predictable across all compilers. It /is/ possible for the byte value
>>>> that usually represents a bool type to be set something that is neither
>>>> true (1) or false (0).
>>>>
>>>
>>> It /is/ undefined behaviour.  (6.2.6.1p5 covers it, though I doubt if
>>> you care.)  It is also common sense.  A _Bool contains either 0 or 1 -
>>> any other value is invalid and can't be achieved without extraordinary
>>> effort designed purely to make bad code.
>>>
>>> Yes, you know /exactly/ what is happening with _Bool - write sane code,
>>> and you get the results you expect.  Write code with clear and
>>> intentional errors with the sole intention of getting inconsistent
>>> results, and you get exactly what you expect.
>>
>> My point is exactly that you don't know what's going on, if not because
>> it's UB, it's because it's implementation defined or for some other
>> weird reason. Take this:
>>
>>     _Bool a=0;
>>
>>     for (int i=0; i<10; ++i){
>>         printf("%d  ",a);
>>         ++a;
>>     }
>>
>> What will be the output? For ++a, it's:
>>
>>   0 1 1 1 1 1 ...
>
> ++a means (a += 1), which in turn means (a = a + 1). The boolean is
> converted to an int (either 0 or 1), and 1 is added giving either 1 or
> 2. Conversion back to _Bool is on the basis of comparison to 0 - since
> neither 1 nor 2 compares equal to 0, the result of "++a" will always
> leave "a" as "true".
>
>>
>> But for --a it's:
>>
>>   0 1 0 1 0 1 ...
>
> Similar reasoning - if "a" is currently "true", then after "--a" it is
> left as "false". If "a" is currently "false", then "a = a - 1" will
> give "a = -1", and thus set "a" to "true" (1).
>
> It's not hard, not UB, not unexpected. (It is also almost certainly not
> found in real code, which is why compilers like gcc with "-Wall" will
> warn you that it's probably a mistake in your code. And in C++, it is
> not allowed at all.)
>

[snip anything about MSVC]

Your explanation is correct, but I still think that Bart has a point.
This example shows that, as it has been designed, _Bool is not
completely a self-consistent type.

There is no reason why a boolean type should behave as shown with ++ and --.

The fact that this is the result of an implicit round trip to and from
'int' shows that _Bool is to some extent still intermingled with 'int',
despite the intention of making a true boolean type to get rid of the
traditional use of 'int' for this purpose.

I know that this is still an extreme example, and I wouldn't write code
like this:

Obviously, if a is a _Bool, "a++" should be replaced with "a = true",
and "a--" should be replaced with "a = !a"

However, the fact that writing "a++" and "a--" is allowed gives Bart a
point, IMO.

>
> The logical and relational operators in C evaluate to "int", values 0 or
> 1, preceding the introduction of _Bool to the language.
>
> The fact that you personally get confused about _Bool and don't
> understand what it is and how it is defined, does not mean that it is
> unclear, confusing, imprecise, or that anyone else fails to comprehend it.
>
> However, now you know the rules that apply even when doing something as
> deliberately unrealistic and pointless as incrementing or decrementing a
> boolean variable. So you can no longer claim that you don't understand
> it, or are not sure what is going on, and can now happily make use of
> this extremely useful type.
>

One might argue that the fact that the rules explain the result do not
make the rules right.

Re: How to avoid an overflow during multiplication?

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

  copy mid

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

  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: Sat, 05 Feb 2022 23:30:11 +0000
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <87y22oriws.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> <86pmojo7th.fsf@linuxsc.com>
<sslpp3$61s$2@gioia.aioe.org> <86sfszlsfd.fsf@linuxsc.com>
<sthe7t$1cph$1@gioia.aioe.org> <86ee4hlwrw.fsf@linuxsc.com>
<stlk7a$1gp0$1@gioia.aioe.org> <stmglu$pn4$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="0e446f973f2c92db02cb4b2f78bfffb6";
logging-data="9309"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/203rl/dQfqgajgJPK7XQoUuHzsMqY9mQ="
Cancel-Lock: sha1:shazcB3EUDaWbvgfMWkWZ6C/tdw=
sha1:oggdwIHCRyxOWNunwn9cd3eF/Ro=
X-BSB-Auth: 1.b99c2db5655a953da644.20220205233011GMT.87y22oriws.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 5 Feb 2022 23:30 UTC

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

> On 2/5/22 05:40, Mateusz Viste wrote:
>> 2022-02-04 at 21:14 -0800, Tim Rentsch wrote:
> ...
>>> Number 9: array parameters may have 'static' and 'const' etc.
>>> Normally I use array notation (eg, 'int x[]') for parameters
>>> that are treated as arrays rather than as pointers to single
>>> objects. This feature allows length and qualifier information to
>>> be added to the pointer parameter while still retaining array
>>> notation in the parameter declaration.
>>
>> I am not sure I understand this one (and I also never use array
>> notation in function parameters). Are you referring to such construct?
>>
>> void pupa(const char s[]) {
>> printf("%c", s[0]);
>> }
>>
>> Apparently this passes without warnings in both c89 and c99 modes of
>> clang and gcc. But I probably misunderstood you.
>
> He's referring to two separate features that were introduced in C99.
<cut>
> In C99, the committee added the feature that you could put one or more
> qualifiers (const, volatile, or restrict) into the first dimension of a
> pointer parameter declared as if it was an array, and the effect would
> be the same as if the qualifier was used in the appropriate location in
> an ordinary pointer declaration:
>
> int qualified(int array[const]);
>
> means exactly the same thing as
>
> int qualified(const int *array);

I don't think so. It means the same as

int qualified(int *const array);

6.7.6.3 p7:

A declaration of a parameter as "array of type" shall be adjusted to
"qualified pointer to type", where the type qualifiers (if any) are
those specified within the [ and ] of the array type derivation.

It is the implied pointer that is qualified.

<cut>
--
Ben.

Re: How to avoid an overflow during multiplication?

<stnl9u$aut$1@dont-email.me>

  copy mid

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

  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: Sun, 6 Feb 2022 00:11:26 -0500
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <stnl9u$aut$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>
<stip0g$1aii$1@gioia.aioe.org> <stitqj$23u$1@dont-email.me>
<stjvbo$dmc$1@dont-email.me> <stltoc$u8l$1@dont-email.me>
<stm4co$8r8$1@dont-email.me> <stm8i0$422$1@dont-email.me>
<stmt35$o14$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 6 Feb 2022 05:11:26 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="6a96ee756d24bbe7650a66e794433591";
logging-data="11229"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4YVGLoGYVUZgjVofqfLrnpBUGKDc+D8I="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:GtOgM/PikDHyN3UyjB7bFz26XQ0=
In-Reply-To: <stmt35$o14$1@gioia.aioe.org>
Content-Language: en-US
 by: James Kuyper - Sun, 6 Feb 2022 05:11 UTC

On 2/5/22 17:18, Manfred wrote:
> On 2/5/22 5:27 PM, David Brown wrote:
....
> There is no reason why a boolean type should behave as shown with ++ and --.
>
> The fact that this is the result of an implicit round trip to and from
> 'int' shows that _Bool is to some extent still intermingled with 'int',
> despite the intention of making a true boolean type to get rid of the
> traditional use of 'int' for this purpose.

Well, what would you expect when applying arithmetic operators to
boolean values? If I weren't familiar with the C standard's
specifications for such things, I wouldn't have any expectations at all
- you shouldn't use such operators on boolean values.

....
>> However, now you know the rules that apply even when doing something as
>> deliberately unrealistic and pointless as incrementing or decrementing a
>> boolean variable. So you can no longer claim that you don't understand
>> it, or are not sure what is going on, and can now happily make use of
>> this extremely useful type.
>>
>
> One might argue that the fact that the rules explain the result do not
> make the rules right.

The committee is the ultimate authority with respect to the C standard -
there's no other authority against which their decisions can be compared
for correctness. You can say it's poorly designed, internally
inconsistent, inconsistent with existing architectures or other computer
languages, etc.; but to say it's wrong implies a standard of correctness
it can be compared with, and there is none. In C, the ++ operator does
what the C standard says it should do - you can decide whether or not
what it does is useful for you, but there's no basis for saying that
what the standard says about it is wrong.

Re: How to avoid an overflow during multiplication?

<stnlm5$ckj$1@dont-email.me>

  copy mid

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

  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: Sun, 6 Feb 2022 00:17:57 -0500
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <stnlm5$ckj$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>
<stlk7a$1gp0$1@gioia.aioe.org> <stmglu$pn4$1@dont-email.me>
<87y22oriws.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 6 Feb 2022 05:17:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="6a96ee756d24bbe7650a66e794433591";
logging-data="12947"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+11rVJhEvbG0OU49o2i4VSdPOuy/Lusr8="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:YLiQxfQmXtCflWum2CTxYEjDKbo=
In-Reply-To: <87y22oriws.fsf@bsb.me.uk>
Content-Language: en-US
 by: James Kuyper - Sun, 6 Feb 2022 05:17 UTC

On 2/5/22 18:30, Ben Bacarisse wrote:
> James Kuyper <jameskuyper@alumni.caltech.edu> writes:
....
>> In C99, the committee added the feature that you could put one or more
>> qualifiers (const, volatile, or restrict) into the first dimension of a
>> pointer parameter declared as if it was an array, and the effect would
>> be the same as if the qualifier was used in the appropriate location in
>> an ordinary pointer declaration:
>>
>> int qualified(int array[const]);
>>
>> means exactly the same thing as
>>
>> int qualified(const int *array);
>
> I don't think so. It means the same as
>
> int qualified(int *const array);
>
> 6.7.6.3 p7:
>
> A declaration of a parameter as "array of type" shall be adjusted to
> "qualified pointer to type", where the type qualifiers (if any) are
> those specified within the [ and ] of the array type derivation.
>
> It is the implied pointer that is qualified.

You're right, of course. I remembered it backwards, and didn't check. I
should have realized my mistake, because the feature wouldn't be needed
if it worked the way I specified - qualifiers before the '*' can be
specified just as easily when declaring a pointer parameter as if it
were an array, as when declaring it explicitly as a pointer.

Re: How to avoid an overflow during multiplication?

<sto9pe$lbp$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sun, 6 Feb 2022 12:01:01 +0100
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <sto9pe$lbp$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>
<stip0g$1aii$1@gioia.aioe.org> <stitqj$23u$1@dont-email.me>
<stjvbo$dmc$1@dont-email.me> <stltoc$u8l$1@dont-email.me>
<stm4co$8r8$1@dont-email.me> <stm8i0$422$1@dont-email.me>
<stm9ci$9k6$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 6 Feb 2022 11:01:02 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3a1549fc778528cd0da64fb323b4b20e";
logging-data="21881"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/H/WvH/rxPskENih7b2fmMMDYdJsBUvzI="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:gnhbHQimbmtGN5l7Hlm+InBKZnI=
In-Reply-To: <stm9ci$9k6$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Sun, 6 Feb 2022 11:01 UTC

On 05/02/2022 17:41, Bart wrote:
> On 05/02/2022 16:27, David Brown wrote:
>> On 05/02/2022 16:16, Bart wrote:
>
>> The fact that you personally get confused about _Bool and don't
>> understand what it is and how it is defined, does not mean that it is
>> unclear, confusing, imprecise, or that anyone else fails to comprehend
>> it.
>>
>> However, now you know the rules that apply even when doing something as
>> deliberately unrealistic and pointless as incrementing or decrementing a
>> boolean variable.  So you can no longer claim that you don't understand
>> it, or are not sure what is going on, and can now happily make use of
>> this extremely useful type.
>
> OK, so I see _Bool used in APIs which I might want to call via an FFI.
>
> Which more universal type is most likely to correspond to it? What are
> the actual values I can expect to see across all bits? What assumptions
> can I make?
>
> I'd quite like to know those answers when coding in C too!

When calling an API that takes a _Bool parameter, you follow whatever
the ABI for the platform says. I would expect that in most cases (I
don't know of any exceptions, but I haven't looked - and I'd be glad to
hear of them), a _Bool takes the same space and ABI conventions as an
unsigned char. So you can simply pass an unsigned char with value 0 or
1. But you do have to make sure it is either 0 or 1, nothing else.

When writing an FFI handler, /you/ are responsible for finding, reading
and understanding the appropriate ABI documents. C "_Bool" and C++
"bool" will be included there.

Re: How to avoid an overflow during multiplication?

<stoi66$huv$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sun, 6 Feb 2022 13:24:23 +0000
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <stoi66$huv$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>
<stip0g$1aii$1@gioia.aioe.org> <stitqj$23u$1@dont-email.me>
<stjvbo$dmc$1@dont-email.me> <stltoc$u8l$1@dont-email.me>
<stm4co$8r8$1@dont-email.me> <stm8i0$422$1@dont-email.me>
<stm9ci$9k6$1@dont-email.me> <sto9pe$lbp$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 6 Feb 2022 13:24:22 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3695410f88fd4ead6a093a340fdaf2d1";
logging-data="18399"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18n/V4pZVuFisvT/y+KByU2mvcmX5QP338="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:TDMRr3BQcjoMGjGzndGhjnk9+vQ=
In-Reply-To: <sto9pe$lbp$1@dont-email.me>
 by: Bart - Sun, 6 Feb 2022 13:24 UTC

On 06/02/2022 11:01, David Brown wrote:
> On 05/02/2022 17:41, Bart wrote:
>> On 05/02/2022 16:27, David Brown wrote:
>>> On 05/02/2022 16:16, Bart wrote:
>>
>>> The fact that you personally get confused about _Bool and don't
>>> understand what it is and how it is defined, does not mean that it is
>>> unclear, confusing, imprecise, or that anyone else fails to comprehend
>>> it.
>>>
>>> However, now you know the rules that apply even when doing something as
>>> deliberately unrealistic and pointless as incrementing or decrementing a
>>> boolean variable.  So you can no longer claim that you don't understand
>>> it, or are not sure what is going on, and can now happily make use of
>>> this extremely useful type.
>>
>> OK, so I see _Bool used in APIs which I might want to call via an FFI.
>>
>> Which more universal type is most likely to correspond to it? What are
>> the actual values I can expect to see across all bits? What assumptions
>> can I make?
>>
>> I'd quite like to know those answers when coding in C too!
>
> When calling an API that takes a _Bool parameter, you follow whatever
> the ABI for the platform says. I would expect that in most cases (I
> don't know of any exceptions, but I haven't looked - and I'd be glad to
> hear of them), a _Bool takes the same space and ABI conventions as an
> unsigned char. So you can simply pass an unsigned char with value 0 or
> 1. But you do have to make sure it is either 0 or 1, nothing else.
>
> When writing an FFI handler, /you/ are responsible for finding, reading
> and understanding the appropriate ABI documents. C "_Bool" and C++
> "bool" will be included there.

The Win64 ABI mentions little about the actual types of primitives,
which is as it should be. It's mainly about sizes, and whether they are
floats or not. It should be language-neutral.

The System V x64 ABI starts with a long list of C types, which sounds
off - why make a special case for C, and not for any of innumerable
other languages? But this is Unix, where everyone knows that Unix and C
are very chummy.

In any case, the API is not the ABI. At the point at which I need to
choose a corresponding type to _Bool in the API, and have to be aware of
representation and semantics, I will not know the target, and therefore
the ABI.

For example, the SYSV ABI for x64 tells me that 'long' is a 64-bit type,
but that's not correct for Windows nor 32-bit Linux.

So the answer seems to be to just make assumptions.

BTW within Windows APIs, 'BOOL' is defined on top of 'int'.

Re: How to avoid an overflow during multiplication?

<stokem$i37$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sun, 6 Feb 2022 15:03:01 +0100
Organization: A noiseless patient Spider
Lines: 187
Message-ID: <stokem$i37$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>
<stip0g$1aii$1@gioia.aioe.org> <stitqj$23u$1@dont-email.me>
<stjvbo$dmc$1@dont-email.me> <stltoc$u8l$1@dont-email.me>
<stm4co$8r8$1@dont-email.me> <stm8i0$422$1@dont-email.me>
<stmt35$o14$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 6 Feb 2022 14:03:02 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3a1549fc778528cd0da64fb323b4b20e";
logging-data="18535"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/mS+2Wn6MXc+zmxyhYPnWI4WNt7lzXXuQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:dVMUQ7Xo/9XpjEl6D9SFv2zUTSg=
In-Reply-To: <stmt35$o14$1@gioia.aioe.org>
Content-Language: en-GB
 by: David Brown - Sun, 6 Feb 2022 14:03 UTC

On 05/02/2022 23:18, Manfred wrote:
> On 2/5/22 5:27 PM, David Brown wrote:
>> On 05/02/2022 16:16, Bart wrote:
>>> On 05/02/2022 13:23, David Brown wrote:
>>>> On 04/02/2022 20:38, Bart wrote:
>>>>> On 04/02/2022 10:06, David Brown wrote:
>>>>
>>>>>> Secondly, there are technical differences.  The conversion of an
>>>>>> integer
>>>>>> "x" to a _Bool "b" is effectively "b = !!x;".  You are guaranteed
>>>>>> that
>>>>>> "b" is either 0 or 1 - and the compiler can use that knowledge for
>>>>>> optimisation (as can the programmer).  This can mean some operations
>>>>>> (such as conversion from an integer) may be less efficient, but other
>>>>>> operations (such as logical operations) are more efficient.
>>>>>> Overall, it
>>>>>> is usually a win.
>>>>>
>>>>> You're never really quite sure what's happening with _Bool.
>>>>>
>>>>> There's little control over its size. And in A program like this:
>>>>>
>>>>>       union {
>>>>>           _Bool a;
>>>>>           unsigned char b;
>>>>>       } x;
>>>>>
>>>>>       x.b=0x55;
>>>>>       printf("A= %X\n", x.a);
>>>>>       printf("B= %X\n", x.b);
>>>>>
>>>>
>>>> <snip>
>>>>
>>>>> You can probably claim this is due to UB or whatever, but the fact
>>>>> remains that using regular int types, the results will be
>>>>> consistent and
>>>>> predictable across all compilers. It /is/ possible for the byte value
>>>>> that usually represents a bool type to be set something that is
>>>>> neither
>>>>> true (1) or false (0).
>>>>>
>>>>
>>>> It /is/ undefined behaviour.  (6.2.6.1p5 covers it, though I doubt if
>>>> you care.)  It is also common sense.  A _Bool contains either 0 or 1 -
>>>> any other value is invalid and can't be achieved without extraordinary
>>>> effort designed purely to make bad code.
>>>>
>>>> Yes, you know /exactly/ what is happening with _Bool - write sane code,
>>>> and you get the results you expect.  Write code with clear and
>>>> intentional errors with the sole intention of getting inconsistent
>>>> results, and you get exactly what you expect.
>>>
>>> My point is exactly that you don't know what's going on, if not because
>>> it's UB, it's because it's implementation defined or for some other
>>> weird reason. Take this:
>>>
>>>      _Bool a=0;
>>>
>>>      for (int i=0; i<10; ++i){
>>>          printf("%d  ",a);
>>>          ++a;
>>>      }
>>>
>>> What will be the output? For ++a, it's:
>>>
>>>    0 1 1 1 1 1 ...
>>
>> ++a means (a += 1), which in turn means (a = a + 1).  The boolean is
>> converted to an int (either 0 or 1), and 1 is added giving either 1 or
>> 2.  Conversion back to _Bool is on the basis of comparison to 0 - since
>> neither 1 nor 2 compares equal to 0, the result of "++a" will always
>> leave "a" as "true".
>>
>>>
>>> But for --a it's:
>>>
>>>    0 1 0 1 0 1 ...
>>
>> Similar reasoning - if "a" is currently "true", then after "--a" it is
>> left as "false".  If "a" is currently "false", then "a = a - 1" will
>> give "a = -1", and thus set "a" to "true" (1).
>>
>> It's not hard, not UB, not unexpected.  (It is also almost certainly not
>> found in real code, which is why compilers like gcc with "-Wall" will
>> warn you that it's probably a mistake in your code.  And in C++, it is
>> not allowed at all.)
>>
>
> [snip anything about MSVC]
>
> Your explanation is correct, but I still think that Bart has a point.
> This example shows that, as it has been designed, _Bool is not
> completely a self-consistent type.

I don't agree. What is inconsistent about it?

>
> There is no reason why a boolean type should behave as shown with ++ and
> --.

Yes, there is - it is the only sensible and consistent possibility for
C. _Bool is an unsigned integer type - any integer types whose values
are a subset of those of "int" get promoted to "int" before arithmetic
operations. You might not think that's the best way to design a
programming language (and you would certainly not be alone in that), but
it is the way C works.

C philosophy has always been to change as little of the existing
language as possible when adding new features - the behaviour of _Bool
in C was made to keep the definitions of operators unchanged.

When C++ was designed, they could take more freedoms - "bool" was there
from the start, and there was less need for compatibility with C
standards. Relational operators in C++ evaluate to a "bool", rather
than an "int", which is more sensible - but C could not make that change
without affecting the existing language and code.

As far as I know (and I haven't checked all the details), "--a" and
"a--" has never been allowed for booleans in C++, while "++a" and "a++"
were removed in C++17.

>
> The fact that this is the result of an implicit round trip to and from
> 'int' shows that _Bool is to some extent still intermingled with 'int',
> despite the intention of making a true boolean type to get rid of the
> traditional use of 'int' for this purpose.

Welcome to C :-)

It is no different from "char" or "short int" in this respect.

"_Bool" is not a strong boolean type, in the manner of - say - Pascal or
Ada. It is not as independent as in C++. It was made such that the
majority of code that used an "int" (or a char of some sort, or an
enumeration) to hold a boolean value could be changed to use _Bool and
still work the same - without causing other disruption to code. And in
additional to standardising a boolean type, it added the useful property
of always being 0 or 1.

>
> I know that this is still an extreme example, and I wouldn't write code
> like this:
>
> Obviously, if a is a _Bool, "a++" should be replaced with "a = true",
> and "a--" should be replaced with "a = !a"
>
> However, the fact that writing "a++" and "a--" is allowed gives Bart a
> point, IMO.
>

Bart's "point" was that _Bool is difficult to understand, unpredictable,
and varies between toolchains. He is wrong in almost all of that. (The
one thing that is correct is that the size of _Bool is
implementation-dependent - it is not necessarily 1.)

If you want to make the point that C's _Bool is not quite the ideal way
to have booleans in a programming language, then I'd agree - C++'s
version is better in several ways. But it is the best that could be
done in an addition to the C language, and the result is an extremely
useful type that C programmers use regularly.

>>
>> The logical and relational operators in C evaluate to "int", values 0 or
>> 1, preceding the introduction of _Bool to the language.
>>
>> The fact that you personally get confused about _Bool and don't
>> understand what it is and how it is defined, does not mean that it is
>> unclear, confusing, imprecise, or that anyone else fails to comprehend
>> it.
>>
>> However, now you know the rules that apply even when doing something as
>> deliberately unrealistic and pointless as incrementing or decrementing a
>> boolean variable.  So you can no longer claim that you don't understand
>> it, or are not sure what is going on, and can now happily make use of
>> this extremely useful type.
>>
>
> One might argue that the fact that the rules explain the result do not
> make the rules right.

You could argue that the rules are not the best choice if designing a
programming language from scratch, and including a boolean type at the
beginning. There's a lot about the rules of C that people disagree with
(though they will disagree about what they disagree with). However, C
is the language defined by the standards - it works well for a lot of
purposes. _Bool fits that perfectly.


Click here to read the complete article
Re: How to avoid an overflow during multiplication?

<stol5p$s6q$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sun, 6 Feb 2022 15:15:20 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <stol5p$s6q$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>
<stip0g$1aii$1@gioia.aioe.org> <stitqj$23u$1@dont-email.me>
<stjvbo$dmc$1@dont-email.me> <stltoc$u8l$1@dont-email.me>
<stm4co$8r8$1@dont-email.me>
<3b6f2718-aff3-4d04-b44b-fb65ebcdef32n@googlegroups.com>
<stmdqj$6sj$1@dont-email.me> <mmzLJ.10298$r6p7.6237@fx41.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 6 Feb 2022 14:15:21 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3a1549fc778528cd0da64fb323b4b20e";
logging-data="28890"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/movoQybuIcO+SGpzZxSIjIC+gQQU1lWw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:Ppn3zmMJ6ccHRzMaKFlFZza80Bo=
In-Reply-To: <mmzLJ.10298$r6p7.6237@fx41.iad>
Content-Language: en-GB
 by: David Brown - Sun, 6 Feb 2022 14:15 UTC

On 05/02/2022 19:29, Richard Damon wrote:
> On 2/5/22 12:57 PM, Bart wrote:
>>
>> It doesn't explain the behaviour of MSVC [19.28.29337 for x64], which
>> outputs all zeros. Maybe another non-conforming one?
>
> Could the code have been compiled as C++, it uses different rules.
>
> If I remember right, in C++ if x is a bool, then x-- is defined to set x
> false and return the previous value of x, a test and clear instruction.

As far as I can tell, pre- and post-decrement of booleans have never
been allowed in C++. Pre- and post-increment give "true", matching C.

This is from C++14 (since I happen to have it open) 5.2.6p2 :

"""
The operand of postfix -- is decremented analogously to the postfix ++
operator, except that the operand shall not be of type bool.
"""

It says the same thing about pre-decrement. Both pre- and
post-increment were deprecated, and removed in C++17.

I think perhaps for his MSVC test, Bart used "BOOL", which is one of the
Windows API's specific types made for C90, and is a typedef for "int".

Re: How to avoid an overflow during multiplication?

<stoli5$41r$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sun, 6 Feb 2022 15:21:56 +0100
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <stoli5$41r$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>
<stlk7a$1gp0$1@gioia.aioe.org> <stmglu$pn4$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 6 Feb 2022 14:21:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3a1549fc778528cd0da64fb323b4b20e";
logging-data="4155"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/OivtfESwPfBxCao04nQvay/peMkoGjrY="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:eh7EC+tlWiWiwqkpd4mUC6ibStg=
In-Reply-To: <stmglu$pn4$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Sun, 6 Feb 2022 14:21 UTC

On 05/02/2022 19:46, James Kuyper wrote:

> The other feature is that you can declare a function parameter as follows:
>
> double limited(float [static 36]);
>
> "If the keyword static also appears within the [ and ] of the array type
> derivation, then for each call to the function, the value of the
> corresponding actual argument shall provide access to the first element
> of an array with at least as many elements as specified by the size
> expression." (7.5.3p7).
>
> Violating this "shall" has undefined behavior (4p2), which doesn't sound
> like much of an advantage. However, that also allows implementations to
> warn you with a diagnostic, if they can determine that your code might
> violate that requirement. If they can determine that it will
> unconditionally violate that requirement, they can even reject the
> program at compile time. It's that non-mandatory diagnostic that I
> consider valuable. It cannot, unfortunately, be made mandatory, because
> in many cases it's difficult, and often even impossible, to determine at
> compile time whether a piece of code will violate that requirement. But
> when it can be determined, I consider that a very valuable warning. YMMV.
>

This would also mean that :

double limited(float [static 1]);

is equivalent to :

double limited(float *);

except that you may not pass a null pointer to a call in the first case.
Again, this gives the compiler a chance to do some more helpful
diagnostics (as well as documenting requirement in the code).

Re: How to avoid an overflow during multiplication?

<stom95$hrc$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sun, 6 Feb 2022 14:34:14 +0000
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <stom95$hrc$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>
<stip0g$1aii$1@gioia.aioe.org> <stitqj$23u$1@dont-email.me>
<stjvbo$dmc$1@dont-email.me> <stltoc$u8l$1@dont-email.me>
<stm4co$8r8$1@dont-email.me>
<3b6f2718-aff3-4d04-b44b-fb65ebcdef32n@googlegroups.com>
<stmdqj$6sj$1@dont-email.me> <mmzLJ.10298$r6p7.6237@fx41.iad>
<stol5p$s6q$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 6 Feb 2022 14:34:13 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3695410f88fd4ead6a093a340fdaf2d1";
logging-data="18284"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18vyanPwkCA/DNbbgGGmq4UN4XSVOz/yqo="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:JN97QrBazhm3akJ6fE+LDpL3oKg=
In-Reply-To: <stol5p$s6q$1@dont-email.me>
 by: Bart - Sun, 6 Feb 2022 14:34 UTC

On 06/02/2022 14:15, David Brown wrote:
> On 05/02/2022 19:29, Richard Damon wrote:
>> On 2/5/22 12:57 PM, Bart wrote:
>>>
>>> It doesn't explain the behaviour of MSVC [19.28.29337 for x64], which
>>> outputs all zeros. Maybe another non-conforming one?
>>
>> Could the code have been compiled as C++, it uses different rules.
>>
>> If I remember right, in C++ if x is a bool, then x-- is defined to set x
>> false and return the previous value of x, a test and clear instruction.
>
> As far as I can tell, pre- and post-decrement of booleans have never
> been allowed in C++. Pre- and post-increment give "true", matching C.
>
>
> This is from C++14 (since I happen to have it open) 5.2.6p2 :
>
> """
> The operand of postfix -- is decremented analogously to the postfix ++
> operator, except that the operand shall not be of type bool.
> """
>
> It says the same thing about pre-decrement. Both pre- and
> post-increment were deprecated, and removed in C++17.
>
>
> I think perhaps for his MSVC test, Bart used "BOOL", which is one of the
> Windows API's specific types made for C90, and is a typedef for "int".

All tests used _Bool.

BOOL, defined as int, would have given results of 0 1 2 3 ... for ++a,
and 0 -1 -2 -3 ... for --a.

(I don't know how to put MSVC into C mode, but I suspect it already is.
A couple of 1000-line C programs, with .c extensions, that fail with
g++, pass with gcc and MSVC.

Also, while MSVC compiles a C++ hello-world program when it has a .cpp
extension, it fails dramatically if I change to a .c extension. All my
tests were .c files.)

Re: How to avoid an overflow during multiplication?

<stp1bl$mq9$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!Puiiztk9lHEEQC0y3uUjRA.user.46.165.242.75.POSTED!not-for-mail
From: non...@add.invalid (Manfred)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sun, 6 Feb 2022 18:43:16 +0100
Organization: Aioe.org NNTP Server
Message-ID: <stp1bl$mq9$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> <sti5s0$dtj$1@dont-email.me>
<stip0g$1aii$1@gioia.aioe.org> <stitqj$23u$1@dont-email.me>
<stjvbo$dmc$1@dont-email.me> <stltoc$u8l$1@dont-email.me>
<stm4co$8r8$1@dont-email.me> <stm8i0$422$1@dont-email.me>
<stmt35$o14$1@gioia.aioe.org> <stnl9u$aut$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="23369"; posting-host="Puiiztk9lHEEQC0y3uUjRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.1
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Manfred - Sun, 6 Feb 2022 17:43 UTC

On 2/6/2022 6:11 AM, James Kuyper wrote:
> On 2/5/22 17:18, Manfred wrote:
>> On 2/5/22 5:27 PM, David Brown wrote:
> ...
>> There is no reason why a boolean type should behave as shown with ++ and --.
>>
>> The fact that this is the result of an implicit round trip to and from
>> 'int' shows that _Bool is to some extent still intermingled with 'int',
>> despite the intention of making a true boolean type to get rid of the
>> traditional use of 'int' for this purpose.
>
> Well, what would you expect when applying arithmetic operators to
> boolean values? If I weren't familiar with the C standard's
> specifications for such things, I wouldn't have any expectations at all
> - you shouldn't use such operators on boolean values.

Exactly, and I add that from the same perspective it would be better if
arithmetic operators on boolean types weren't allowed by the language.
Allowing them might open some niche corner use case, but at the same
time it exposes the language to a critique about consistency like
Bart's, which, as I said, has in fact some grounds.

>
> ...
>>> However, now you know the rules that apply even when doing something as
>>> deliberately unrealistic and pointless as incrementing or decrementing a
>>> boolean variable. So you can no longer claim that you don't understand
>>> it, or are not sure what is going on, and can now happily make use of
>>> this extremely useful type.
>>>
>>
>> One might argue that the fact that the rules explain the result do not
>> make the rules right.
>
> The committee is the ultimate authority with respect to the C standard -
> there's no other authority against which their decisions can be compared
> for correctness. You can say it's poorly designed, internally
> inconsistent, inconsistent with existing architectures or other computer
> languages, etc.; but to say it's wrong implies a standard of correctness
> it can be compared with, and there is none. In C, the ++ operator does
> what the C standard says it should do - you can decide whether or not
> what it does is useful for you, but there's no basis for saying that
> what the standard says about it is wrong.

While I was writing that last sentence I've been wondering about the
word "right" because of the meaning you reply at.
I meant "right" as "well done", "smart", "well designed" etc.
I think it was clear because the sentence is about "rules": rules are,
by definition, mandatory, hence your meaning for "correctness" is
implicit in the definition of "rule".
Therefore, arguing about whether a rule is right or wrong is about the
rule being well designed, thought of, chosen or not.

In a sense, it's like with law in civil life: you have to abide to all
laws, and it is right to do so - but at the same time one is allowed to
say if some law, in their opinion, is not right, just or fair. The
former part is about cohabitation in a civil society, the latter is
about (the right for) critical thought.

Lots of "right"'s here...
(I like the English language, even if I am not a native English speaker,
however I think one of its weaknesses is the more limited vocabulary
compared to other languages)

Re: How to avoid an overflow during multiplication?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: How to avoid an overflow during multiplication?
Date: Sun, 06 Feb 2022 12:56:16 -0800
Organization: None to speak of
Lines: 21
Message-ID: <87r18fk93j.fsf@nosuchdomain.example.com>
References: <sqmkg9$157v$1@gioia.aioe.org> <sqq0lb$1g77$1@gioia.aioe.org>
<86v8ydp57h.fsf@linuxsc.com> <ssehod$hfk$1@gioia.aioe.org>
<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> <stip0g$1aii$1@gioia.aioe.org>
<stitqj$23u$1@dont-email.me> <stjvbo$dmc$1@dont-email.me>
<stltoc$u8l$1@dont-email.me> <stm4co$8r8$1@dont-email.me>
<3b6f2718-aff3-4d04-b44b-fb65ebcdef32n@googlegroups.com>
<stmdqj$6sj$1@dont-email.me> <mmzLJ.10298$r6p7.6237@fx41.iad>
<stol5p$s6q$1@dont-email.me> <stom95$hrc$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="2f96dbfac24bbd0b93afa42e4fb58430";
logging-data="9764"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX188dFiWDZ7lY07pHI0bWJss"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:kYJa0R8+D/YrdTG97zDZAfasbpM=
sha1:BOPglBLEKIIp86ezI8cza6CTYXI=
 by: Keith Thompson - Sun, 6 Feb 2022 20:56 UTC

Bart <bc@freeuk.com> writes:
[...]
> (I don't know how to put MSVC into C mode, but I suspect it already
> is. A couple of 1000-line C programs, with .c extensions, that fail
> with g++, pass with gcc and MSVC.

You can confirm this by using "class" as an identifier, or, if you want
to be more explicit, something like this:

#ifdef __cplusplus
#error "Compiled as C++"
#endif

> Also, while MSVC compiles a C++ hello-world program when it has a .cpp
> extension, it fails dramatically if I change to a .c extension. All my
> tests were .c files.)

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

Re: How to avoid an overflow during multiplication?

<stpgso$op1$1@dont-email.me>

  copy mid

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

  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: Sun, 6 Feb 2022 22:08:24 +0000
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <stpgso$op1$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 6 Feb 2022 22:08:24 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="cb04cf2bdd9dcac722ef85bc03c8c91a";
logging-data="25377"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19i0NMR4WI/prMplNjWDAule0A4k2PgFpE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:6aBxdjDvhCVbzO1qYE+3DQE5uoI=
In-Reply-To: <sthm4i$d2b$1@gioia.aioe.org>
Content-Language: en-GB
 by: Vir Campestris - Sun, 6 Feb 2022 22:08 UTC

On 03/02/2022 22:48, Mateusz Viste wrote:
> 2022-02-03 at 22:28 +0000, Vir Campestris wrote:
>> I use bool all the time; why would you use anything else? It's a type
>> that holds 2 values, and the compiler can pick what to use for your
>> processor. It might be a bit mask, or a 64 bit word. It might even
>> vary with your optimisation settings.
>
> Can you tell what advantage it has over using, say, int_fast8_t?
>

It depends on your machine.

I've worked on machines where to read a byte from memory involves
reading a word, shifting it, then anding with 255.

Writing one back means shifting the byte in a register, reading a word
from memory, ANDing out the old value, ORing the new one, then writing
back the word.

I've also worked on ones, albeit not with C, where a character isn't 8
bits but only 6.

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.

Andy

Re: How to avoid an overflow during multiplication?

<stqk7g$go3$1@gioia.aioe.org>

  copy mid

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

  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:11:28 +0100
Organization: . . .
Message-ID: <stqk7g$go3$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>
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:11 UTC

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.

Mateusz

Re: How to avoid an overflow during multiplication?

<stqkc4$go3$2@gioia.aioe.org>

  copy mid

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

  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:13:56 +0100
Organization: . . .
Message-ID: <stqkc4$go3$2@gioia.aioe.org>
References: <sqmkg9$157v$1@gioia.aioe.org>
<8735m954yz.fsf@bsb.me.uk>
<sqn0aq$1e8b$1@gioia.aioe.org>
<unsigned-20211231144041@ram.dialup.fu-berlin.de>
<sqn2dj$14ld$2@gioia.aioe.org>
<877dbk36qu.fsf@nosuchdomain.example.com>
<sqnmsm$1ff8$1@gioia.aioe.org>
<sqo47m$n9p$1@dont-email.me>
<sqq0lb$1g77$1@gioia.aioe.org>
<86v8ydp57h.fsf@linuxsc.com>
<ssehod$hfk$1@gioia.aioe.org>
<86pmojo7th.fsf@linuxsc.com>
<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=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:13 UTC

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) :)

Mateusz

Pages:12345678
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor