Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

C'est magnifique, mais ce n'est pas l'Informatique. -- Bosquet [on seeing the IBM 4341]


devel / comp.lang.c / Re: does a double cast to unsigned makes sense in any circumstance?

SubjectAuthor
* does a double cast to unsigned makes sense in any circumstance?Meredith Montgomery
+* Re: does a double cast to unsigned makes sense in any circumstance?Bart
|`- Re: does a double cast to unsigned makes sense in any circumstance?Meredith Montgomery
+* Re: does a double cast to unsigned makes sense in any circumstance?Andrey Tarasevich
|`* Re: does a double cast to unsigned makes sense in any circumstance?Meredith Montgomery
| `* Re: does a double cast to unsigned makes sense in any circumstance?James Kuyper
|  `* Re: does a double cast to unsigned makes sense in any circumstance?Tim Rentsch
|   `* Re: does a double cast to unsigned makes sense in any circumstance?james...@alumni.caltech.edu
|    `- Re: does a double cast to unsigned makes sense in any circumstance?Tim Rentsch
+* Re: does a double cast to unsigned makes sense in any circumstance?Bonita Montero
|`* Re: does a double cast to unsigned makes sense in any circumstance?Meredith Montgomery
| `* Re: does a double cast to unsigned makes sense in any circumstance?James Kuyper
|  +* Re: does a double cast to unsigned makes sense in any circumstance?Keith Thompson
|  |+- Re: does a double cast to unsigned makes sense in any circumstance?James Kuyper
|  |`* Re: does a double cast to unsigned makes sense in any circumstance?Meredith Montgomery
|  | `* Re: does a double cast to unsigned makes sense in any circumstance?Keith Thompson
|  |  `* Re: does a double cast to unsigned makes sense in any circumstance?Meredith Montgomery
|  |   +* Re: does a double cast to unsigned makes sense in any circumstance?James Kuyper
|  |   |`* Re: does a double cast to unsigned makes sense in any circumstance?Tim Rentsch
|  |   | `- Re: does a double cast to unsigned makes sense in any circumstance?james...@alumni.caltech.edu
|  |   `* Re: does a double cast to unsigned makes sense in any circumstance?Keith Thompson
|  |    `* Re: does a double cast to unsigned makes sense in any circumstance?Manfred
|  |     `* Re: does a double cast to unsigned makes sense in any circumstance?Keith Thompson
|  |      `- Re: does a double cast to unsigned makes sense in any circumstance?Richard Damon
|  `- Re: does a double cast to unsigned makes sense in any circumstance?Meredith Montgomery
+* Re: does a double cast to unsigned makes sense in any circumstance?Richard Damon
|+* Re: does a double cast to unsigned makes sense in any circumstance?Meredith Montgomery
||`* Re: does a double cast to unsigned makes sense in any circumstance?Richard Damon
|| `- Re: does a double cast to unsigned makes sense in any circumstance?Meredith Montgomery
|`- Re: does a double cast to unsigned makes sense in any circumstance?Bonita Montero
`* Re: does a double cast to unsigned makes sense in any circumstance?Tim Rentsch
 +- Re: does a double cast to unsigned makes sense in any circumstance?Meredith Montgomery
 `* Re: does a double cast to unsigned makes sense in any circumstance?Bonita Montero
  `* Re: does a double cast to unsigned makes sense in any circumstance?Öö Tiib
   `* Re: does a double cast to unsigned makes sense in any circumstance?Bonita Montero
    `- Re: does a double cast to unsigned makes sense in any circumstance?Öö Tiib

Pages:12
does a double cast to unsigned makes sense in any circumstance?

<86czl8kaew.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!DznC0QdE350DtDa07l4QlA.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: does a double cast to unsigned makes sense in any circumstance?
Date: Mon, 03 Jan 2022 14:15:51 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86czl8kaew.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="10055"; posting-host="DznC0QdE350DtDa07l4QlA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:shLqOunioGS6cMPxo9G/A51sSLo=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Mon, 3 Jan 2022 17:15 UTC

I've seen this somewhere or I wrote this some time in the past for some
reason and I can't see how this make sense any longer. In a procedure
to read a numeric string and turn it into a number, we need to convert
each char-digit to some kind of integer:

(uint64_t) (unsigned char) (s[pos] - '0');

But the double cast here seems odd. I could have written this by
copying it from somewhere else. Today, what I would write is just

(uint64_t) (s[pos] - '0');

Am I making a mistake now? I can't anything wrong with this. Isn't a
char just an int? I'm turning an int into an unsigned integer (of a
larger size).

Thank you!

Re: does a double cast to unsigned makes sense in any circumstance?

<sqvc03$v6n$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Date: Mon, 3 Jan 2022 17:32:51 +0000
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <sqvc03$v6n$1@dont-email.me>
References: <86czl8kaew.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 3 Jan 2022 17:32:51 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="26b793bf8e5a6d3d9dfe41f80f76bfa1";
logging-data="31959"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/kZ/OGxud0IRlZAxd2YBt6x2PhS//lxEM="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.1
Cancel-Lock: sha1:kQYMN1+m9rtnknQ76tvCWJCYvnk=
In-Reply-To: <86czl8kaew.fsf@levado.to>
 by: Bart - Mon, 3 Jan 2022 17:32 UTC

On 03/01/2022 17:15, Meredith Montgomery wrote:
> I've seen this somewhere or I wrote this some time in the past for some
> reason and I can't see how this make sense any longer. In a procedure
> to read a numeric string and turn it into a number, we need to convert
> each char-digit to some kind of integer:
>
> (uint64_t) (unsigned char) (s[pos] - '0');
>
> But the double cast here seems odd. I could have written this by
> copying it from somewhere else. Today, what I would write is just
>
> (uint64_t) (s[pos] - '0');
>
> Am I making a mistake now? I can't anything wrong with this. Isn't a
> char just an int? I'm turning an int into an unsigned integer (of a
> larger size).

Have you tried it? With this code:

signed char c=-10;
printf("%llu\n", (unsigned long long) c);
printf("%llu\n", (unsigned long long) (unsigned char) c);

The output is

18446744073709551606
246

So clearly there's a difference.

(I used 'long long' so that I could use the llu print format with more
confidence.)

Re: does a double cast to unsigned makes sense in any circumstance?

<sqvdud$3tt$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Date: Mon, 3 Jan 2022 10:06:04 -0800
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <sqvdud$3tt$1@dont-email.me>
References: <86czl8kaew.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 3 Jan 2022 18:06:05 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="398550a3c8aa41049bdf52a4d8a9edb4";
logging-data="4029"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18mRErzL5H/8ie6hsC6Ztev"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.1
Cancel-Lock: sha1:To2vRs7ZeXChJaq1C0s7w3V+7Ho=
In-Reply-To: <86czl8kaew.fsf@levado.to>
Content-Language: en-US
 by: Andrey Tarasevich - Mon, 3 Jan 2022 18:06 UTC

On 1/3/2022 9:15 AM, Meredith Montgomery wrote:
> I've seen this somewhere or I wrote this some time in the past for some
> reason and I can't see how this make sense any longer. In a procedure
> to read a numeric string and turn it into a number, we need to convert
> each char-digit to some kind of integer:
>
> (uint64_t) (unsigned char) (s[pos] - '0');
>
> But the double cast here seems odd. I could have written this by
> copying it from somewhere else. Today, what I would write is just
>
> (uint64_t) (s[pos] - '0');
>
> Am I making a mistake now? I can't anything wrong with this. Isn't a
> char just an int? I'm turning an int into an unsigned integer (of a
> larger size).

Yes, it does make sense. For example, if the outer type is wider than
the inner type, as in your example.

A cast to unsigned type is not just a conceptual type change. It also
might transform (wrap) the value in accordance with the rules of modulo
arithmetic, with modulo equal to 2^(type width).

So, the first cast is intended to wrap the value. The second cast is
intended to "expand" the result to a desired target type.

--
Best regards,
Andrey Tarasevich

Re: does a double cast to unsigned makes sense in any circumstance?

<sqvfed$rps$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Date: Mon, 3 Jan 2022 19:31:39 +0100
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <sqvfed$rps$1@dont-email.me>
References: <86czl8kaew.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 3 Jan 2022 18:31:41 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="e86f46db7440dd777d5a3278dff6fd26";
logging-data="28476"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/xEguzATx2YxKgRixWps79L9JA6o4puSY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.1
Cancel-Lock: sha1:3iYDqoZMGO4yh6zpWkLsnZ/42b8=
In-Reply-To: <86czl8kaew.fsf@levado.to>
Content-Language: de-DE
 by: Bonita Montero - Mon, 3 Jan 2022 18:31 UTC

Am 03.01.2022 um 18:15 schrieb Meredith Montgomery:
> I've seen this somewhere or I wrote this some time in the past for some
> reason and I can't see how this make sense any longer. In a procedure
> to read a numeric string and turn it into a number, we need to convert
> each char-digit to some kind of integer:
>
> (uint64_t) (unsigned char) (s[pos] - '0');

(s[pos] - '0') might me signed and without the cast to unsigned
char it might be sign-extended to int64_4 before it is converted
to uint64_t. But there are no guarantees when converting negative
values to unsigneds.

Re: does a double cast to unsigned makes sense in any circumstance?

<0gIAJ.2283$jW.2224@fx05.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx05.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.4.1
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Content-Language: en-US
Newsgroups: comp.lang.c
References: <86czl8kaew.fsf@levado.to>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <86czl8kaew.fsf@levado.to>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 28
Message-ID: <0gIAJ.2283$jW.2224@fx05.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: Mon, 3 Jan 2022 14:37:38 -0500
X-Received-Bytes: 2083
X-Original-Bytes: 1950
 by: Richard Damon - Mon, 3 Jan 2022 19:37 UTC

On 1/3/22 12:15 PM, Meredith Montgomery wrote:
> I've seen this somewhere or I wrote this some time in the past for some
> reason and I can't see how this make sense any longer. In a procedure
> to read a numeric string and turn it into a number, we need to convert
> each char-digit to some kind of integer:
>
> (uint64_t) (unsigned char) (s[pos] - '0');
>
> But the double cast here seems odd. I could have written this by
> copying it from somewhere else. Today, what I would write is just
>
> (uint64_t) (s[pos] - '0');
>
> Am I making a mistake now? I can't anything wrong with this. Isn't a
> char just an int? I'm turning an int into an unsigned integer (of a
> larger size).
>
> Thank you!

As others have said, it does change the behavior, but only if s[pos]
might be less than '0', which means it holds something other than a
digit, as the characters 0..9 are a required to be a consecutive
increase sequence (which the code is likely counting on).

If you know that s[pos] will always be > 0, then the double cast may
produce faster code, as unless the compiler can also determine this, it
may need to first sign extend to int, then zero extend to uint64_t,
verse just zero extending to uint64_t.

Re: does a double cast to unsigned makes sense in any circumstance?

<86h7a4trk3.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!/eRJ076R8qgwl6rQB+gRxA.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Date: Sat, 15 Jan 2022 22:09:16 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86h7a4trk3.fsf@levado.to>
References: <86czl8kaew.fsf@levado.to> <sqvc03$v6n$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="48779"; posting-host="/eRJ076R8qgwl6rQB+gRxA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:MAN9ckcZBv8HKL6g+veyko5z1UU=
 by: Meredith Montgomery - Sun, 16 Jan 2022 01:09 UTC

Bart <bc@freeuk.com> writes:

> On 03/01/2022 17:15, Meredith Montgomery wrote:
>> I've seen this somewhere or I wrote this some time in the past for some
>> reason and I can't see how this make sense any longer. In a procedure
>> to read a numeric string and turn it into a number, we need to convert
>> each char-digit to some kind of integer:
>> (uint64_t) (unsigned char) (s[pos] - '0');
>> But the double cast here seems odd. I could have written this by
>> copying it from somewhere else. Today, what I would write is just
>> (uint64_t) (s[pos] - '0');
>> Am I making a mistake now? I can't anything wrong with this. Isn't
>> a
>> char just an int? I'm turning an int into an unsigned integer (of a
>> larger size).
>
> Have you tried it? With this code:
>
> signed char c=-10;
> printf("%llu\n", (unsigned long long) c);
> printf("%llu\n", (unsigned long long) (unsigned char) c);
>
> The output is
>
> 18446744073709551606
> 246
>
> So clearly there's a difference.

Indeed. Thank you. I had tried it, but I wasn't quite thinking of
negative numbers because I was thinking of just my chars and my chars
are never negative. So the purpose there is to not let the number grow
to 64 bits. That's my understanding right now. Thank you.

Re: does a double cast to unsigned makes sense in any circumstance?

<86bl0ctree.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!/eRJ076R8qgwl6rQB+gRxA.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Date: Sat, 15 Jan 2022 22:12:41 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86bl0ctree.fsf@levado.to>
References: <86czl8kaew.fsf@levado.to> <sqvdud$3tt$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="52949"; posting-host="/eRJ076R8qgwl6rQB+gRxA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:LPs8WRiQUJDSKO6GtxTVL/dmRhw=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Sun, 16 Jan 2022 01:12 UTC

Andrey Tarasevich <andreytarasevich@hotmail.com> writes:

> On 1/3/2022 9:15 AM, Meredith Montgomery wrote:
>> I've seen this somewhere or I wrote this some time in the past for some
>> reason and I can't see how this make sense any longer. In a procedure
>> to read a numeric string and turn it into a number, we need to convert
>> each char-digit to some kind of integer:
>> (uint64_t) (unsigned char) (s[pos] - '0');
>> But the double cast here seems odd. I could have written this by
>> copying it from somewhere else. Today, what I would write is just
>> (uint64_t) (s[pos] - '0');
>> Am I making a mistake now? I can't anything wrong with this. Isn't
>> a
>> char just an int? I'm turning an int into an unsigned integer (of a
>> larger size).
>
> Yes, it does make sense. For example, if the outer type is wider than
> the inner type, as in your example.
>
> A cast to unsigned type is not just a conceptual type change. It also
> might transform (wrap) the value in accordance with the rules of
> modulo arithmetic, with modulo equal to 2^(type width).
>
> So, the first cast is intended to wrap the value. The second cast is
> intended to "expand" the result to a desired target type.

Interesting. I got another question here. If s[pos] is always a char
and '0' is always a char, then s[pos] - '0' will never be greater than a
char. It might be negative. If it's negative and if I do

(unsigner char) s[pos] - '0',

can this do any wrapping at all? I'd say not in this case. I think you
are in more general waters than I took your message. Can you clarify a
bit? I'm a bit lost.

Re: does a double cast to unsigned makes sense in any circumstance?

<8635lotrby.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!/eRJ076R8qgwl6rQB+gRxA.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Date: Sat, 15 Jan 2022 22:14:09 -0300
Organization: Aioe.org NNTP Server
Message-ID: <8635lotrby.fsf@levado.to>
References: <86czl8kaew.fsf@levado.to> <sqvfed$rps$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="52949"; posting-host="/eRJ076R8qgwl6rQB+gRxA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:UhyyO0HuNn/9sHiPZCcDos0tuqE=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Sun, 16 Jan 2022 01:14 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:

> Am 03.01.2022 um 18:15 schrieb Meredith Montgomery:
>> I've seen this somewhere or I wrote this some time in the past for some
>> reason and I can't see how this make sense any longer. In a procedure
>> to read a numeric string and turn it into a number, we need to convert
>> each char-digit to some kind of integer:
>> (uint64_t) (unsigned char) (s[pos] - '0');
>
> (s[pos] - '0') might me signed and without the cast to unsigned
> char it might be sign-extended to int64_4 before it is converted
> to uint64_t. But there are no guarantees when converting negative
> values to unsigneds.

Really, no guarantees? So a procedure that does

(uint64_t) (unsigned char) (s[pos] - '0')

is not a C program if a machine uses negative numbers for chars?

Re: does a double cast to unsigned makes sense in any circumstance?

<86wnj0scpn.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!/eRJ076R8qgwl6rQB+gRxA.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Date: Sat, 15 Jan 2022 22:15:16 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86wnj0scpn.fsf@levado.to>
References: <86czl8kaew.fsf@levado.to> <0gIAJ.2283$jW.2224@fx05.iad>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="52949"; posting-host="/eRJ076R8qgwl6rQB+gRxA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:77GSd47EOmyl+J8uHSyV8mRNjxM=
 by: Meredith Montgomery - Sun, 16 Jan 2022 01:15 UTC

Richard Damon <Richard@Damon-Family.org> writes:

> On 1/3/22 12:15 PM, Meredith Montgomery wrote:
>> I've seen this somewhere or I wrote this some time in the past for some
>> reason and I can't see how this make sense any longer. In a procedure
>> to read a numeric string and turn it into a number, we need to convert
>> each char-digit to some kind of integer:
>> (uint64_t) (unsigned char) (s[pos] - '0');
>> But the double cast here seems odd. I could have written this by
>> copying it from somewhere else. Today, what I would write is just
>> (uint64_t) (s[pos] - '0');
>> Am I making a mistake now? I can't anything wrong with this. Isn't
>> a
>> char just an int? I'm turning an int into an unsigned integer (of a
>> larger size).
>> Thank you!
>
> As others have said, it does change the behavior, but only if s[pos]
> might be less than '0', which means it holds something other than a
> digit, as the characters 0..9 are a required to be a consecutive
> increase sequence (which the code is likely counting on).
>
> If you know that s[pos] will always be > 0, then the double cast may
> produce faster code, as unless the compiler can also determine this,
> it may need to first sign extend to int, then zero extend to uint64_t,
> verse just zero extending to uint64_t.

What do you mean by ``zero extend''? Are you qualifying the verb ``to
extend''? You lost me there. Thank you.

Re: does a double cast to unsigned makes sense in any circumstance?

<eWKEJ.204005$Wkjc.110862@fx35.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx35.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0)
Gecko/20100101 Thunderbird/91.5.0
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Content-Language: en-US
Newsgroups: comp.lang.c
References: <86czl8kaew.fsf@levado.to> <0gIAJ.2283$jW.2224@fx05.iad>
<86wnj0scpn.fsf@levado.to>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <86wnj0scpn.fsf@levado.to>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 50
Message-ID: <eWKEJ.204005$Wkjc.110862@fx35.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, 15 Jan 2022 20:55:23 -0500
X-Received-Bytes: 3404
 by: Richard Damon - Sun, 16 Jan 2022 01:55 UTC

On 1/15/22 8:15 PM, Meredith Montgomery wrote:
> Richard Damon <Richard@Damon-Family.org> writes:
>
>> On 1/3/22 12:15 PM, Meredith Montgomery wrote:
>>> I've seen this somewhere or I wrote this some time in the past for some
>>> reason and I can't see how this make sense any longer. In a procedure
>>> to read a numeric string and turn it into a number, we need to convert
>>> each char-digit to some kind of integer:
>>> (uint64_t) (unsigned char) (s[pos] - '0');
>>> But the double cast here seems odd. I could have written this by
>>> copying it from somewhere else. Today, what I would write is just
>>> (uint64_t) (s[pos] - '0');
>>> Am I making a mistake now? I can't anything wrong with this. Isn't
>>> a
>>> char just an int? I'm turning an int into an unsigned integer (of a
>>> larger size).
>>> Thank you!
>>
>> As others have said, it does change the behavior, but only if s[pos]
>> might be less than '0', which means it holds something other than a
>> digit, as the characters 0..9 are a required to be a consecutive
>> increase sequence (which the code is likely counting on).
>>
>> If you know that s[pos] will always be > 0, then the double cast may
>> produce faster code, as unless the compiler can also determine this,
>> it may need to first sign extend to int, then zero extend to uint64_t,
>> verse just zero extending to uint64_t.
>
> What do you mean by ``zero extend''? Are you qualifying the verb ``to
> extend''? You lost me there. Thank you.

When the processor loads the 8 bit character into the bottom of the
register, it generally leaves the rest of the register alone.

If Char is signed, and int is 32 bits, then the implementation can
convert it to an int by extending the sign of the bottom byte into the
rest of the register, and then to make it a unsigned 54 bit value, it
needs to put zeros into the upper 32 bits of the register.

By casting to unsigned character, then the implentation only needs to
use an instruction that fills the upper 56 bits of the register to 0.

Setting the upper bits of a register with a value is called 'extending'

If it is copying the sign bit of the lower part of the register, it is
called sign extending.

If it is just fixing them to zero, it is called zero extending, because
we are thinking of the always 0 'sign bits' that extend beyond the bits
of the unsigned value.

Re: does a double cast to unsigned makes sense in any circumstance?

<86y23gtmr0.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Date: Sat, 15 Jan 2022 18:53:07 -0800
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <86y23gtmr0.fsf@linuxsc.com>
References: <86czl8kaew.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="66ee21d996f56235c8cdb5e1ea47e716";
logging-data="18658"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+aBhnbKo7S0+2AriiANVbI6NCOCNbRxUg="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:LlvZUS37giR0Jgkn9R+sFIp8yJw=
sha1:LD1SJ4AkCpuEkwlo0YpwfYX3YIU=
 by: Tim Rentsch - Sun, 16 Jan 2022 02:53 UTC

Meredith Montgomery <mmontgomery@levado.to> writes:

> I've seen this somewhere or I wrote this some time in the past for some
> reason and I can't see how this make sense any longer. In a procedure
> to read a numeric string and turn it into a number, we need to convert
> each char-digit to some kind of integer:
>
> (uint64_t) (unsigned char) (s[pos] - '0');
>
> But the double cast here seems odd. I could have written this by
> copying it from somewhere else. Today, what I would write is just
>
> (uint64_t) (s[pos] - '0');
>
> Am I making a mistake now? I can't anything wrong with this. Isn't a
> char just an int? I'm turning an int into an unsigned integer (of a
> larger size).

The original context for the expression in question is this
function:

> [posted by Meredith Montgomery]
>
> #include <limits.h>
> #include <inttypes.h>
>
> int scan_ulong(register char *s, register unsigned long *u)
> {
> register unsigned int pos;
> register unsigned long r;
> register unsigned long c;
>
> pos = 0; r = 0;
>
> for ( ;; ) {
> c = (unsigned long) (unsigned char) (s[pos] - '0');
> if (c < 10) {
> if( ((ULONG_MAX - c) / 10) >= r)
> r = r * 10 + c;
> else return -1; /* lack of space */
> ++pos; continue;
> }
> break;
> }
>
> *u = r;
> return pos;
> }

In this context, the casts are superfluous. Just write

c = s[pos] - '0';

and the right thing will happen, because the assignment to 'c'
converts the value on the right hand side to 'unsigned long',
and so takes care of any negative values.

Re: does a double cast to unsigned makes sense in any circumstance?

<ss0605$e73$1@dont-email.me>

  copy mid

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

  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: does a double cast to unsigned makes sense in any circumstance?
Date: Sat, 15 Jan 2022 23:12:53 -0500
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <ss0605$e73$1@dont-email.me>
References: <86czl8kaew.fsf@levado.to> <sqvdud$3tt$1@dont-email.me>
<86bl0ctree.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 16 Jan 2022 04:12:53 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b4d44b234c67537f75491df926d16248";
logging-data="14563"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+sfMNMsYuIQE+2UEDNlExK5dEiC4cTgbs="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:n1XKc5JMOtK7bMFdeDVaTRD1a8M=
In-Reply-To: <86bl0ctree.fsf@levado.to>
Content-Language: en-US
 by: James Kuyper - Sun, 16 Jan 2022 04:12 UTC

On 1/15/22 8:12 PM, Meredith Montgomery wrote:
....
> Interesting. I got another question here. If s[pos] is always a char
> and '0' is always a char, then s[pos] - '0' will never be greater than a
> char. It might be negative. If it's negative and if I do

Note that while members of the basic character set are required to be
represented by non-negative values (6.2.5p3), members of the extended
character set are not. If char is signed, they can be as low as
CHAR_MIN, in which case subtracting '0' necessarily results in undefined
behavior. The following discussion applies only when that isn't the case:

> (unsigner char) s[pos] - '0',
>
> can this do any wrapping at all? I'd say not in this case. I think you
> are in more general waters than I took your message. Can you clarify a
> bit? I'm a bit lost.

Subtraction involves (6.5p6) the usual arithmetic conversions
(6.3.1.8p1), and the first part of that is the integer promotions
(6.3.1.1p2). Both overflow and wrap-around are possible results, but
only on systems where CHAR_BIT >= 16. Such systems do exist - the ones
I've heard of are embedded systems specialized for digital signal
processing.

If all values of type unsigned char can be represented as an int,
(unsigned char)s[pos] will be promoted to int before performing the
subtraction (6.3.1.1p2). In the unlikely event that CHAR_MAX == INT_MAX,
(int)(unsigned char)s[pos] will have the same value as s[pos].
Therefore, if s[pos] is sufficiently close to INT_MIN, subtracting '0'
from it will have undefined behavior.

In the unlikely event that UCHAR_MAX > INT_MAX, s[pos] is promoted to an
unsigned int (6.3.1.1p2). Since '0' has the type 'int', and 'int' and
unsigned int' have the same integer conversion rank, the usual
arithmetic conversions specify that '0' is converted to unsigned int,
and the subtraction is carried out in that type. If s[pos] is less than
'0', then s[pos] - '0' will have a mathematical value that is negative,
so it will have to wrap around.

Re: does a double cast to unsigned makes sense in any circumstance?

<ss060d$e1s$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Date: Sun, 16 Jan 2022 05:13:01 +0100
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <ss060d$e1s$1@dont-email.me>
References: <86czl8kaew.fsf@levado.to> <0gIAJ.2283$jW.2224@fx05.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 16 Jan 2022 04:13:01 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3e13535bf9c210bf9b2b5c4f57bf43da";
logging-data="14396"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18v6d4mCEP0CkkFLlK7w4mzRx1AG3nvZVE="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:X0x0Wgqdm6ACvDwALEx1xeH0Lm0=
In-Reply-To: <0gIAJ.2283$jW.2224@fx05.iad>
Content-Language: de-DE
 by: Bonita Montero - Sun, 16 Jan 2022 04:13 UTC

Am 03.01.2022 um 20:37 schrieb Richard Damon:

> If you know that s[pos] will always be > 0, then the double cast may
> produce faster code, as unless the compiler can also determine this,
> it may need to first sign extend to int, then zero extend to uint64_t,
> verse just zero extending to uint64_t.

On x86 there are widening-instructions to zero- / sign-extend a shorter
value which have all the same performance.

Re: does a double cast to unsigned makes sense in any circumstance?

<ss06le$h5n$1@dont-email.me>

  copy mid

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

  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: does a double cast to unsigned makes sense in any circumstance?
Date: Sat, 15 Jan 2022 23:24:13 -0500
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <ss06le$h5n$1@dont-email.me>
References: <86czl8kaew.fsf@levado.to> <sqvfed$rps$1@dont-email.me>
<8635lotrby.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 16 Jan 2022 04:24:15 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b4d44b234c67537f75491df926d16248";
logging-data="17591"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/P4s5d4hg6udphQwEZ87nrz9REAmDLaDc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:Lvd2QsqO6pi5/UzBOPBYpIRGi7c=
In-Reply-To: <8635lotrby.fsf@levado.to>
Content-Language: en-US
 by: James Kuyper - Sun, 16 Jan 2022 04:24 UTC

On 1/15/22 8:14 PM, Meredith Montgomery wrote:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>
>> Am 03.01.2022 um 18:15 schrieb Meredith Montgomery:
>>> I've seen this somewhere or I wrote this some time in the past for some
>>> reason and I can't see how this make sense any longer. In a procedure
>>> to read a numeric string and turn it into a number, we need to convert
>>> each char-digit to some kind of integer:
>>> (uint64_t) (unsigned char) (s[pos] - '0');
>>
>> (s[pos] - '0') might me signed and without the cast to unsigned
>> char it might be sign-extended to int64_4 before it is converted
>> to uint64_t. ...

He's right about it being signed - that's normally the case. It normally
has the type `int`, except in the extremely unlikely case that CHAR_MAX
> INT_MAX, in which case it will have the type `unsigned int`. However,
int64_t comes into play only if it's typedef for `int`.

>> ... But there are no guarantees when converting negative
>> values to unsigneds.
>
> Really, no guarantees? So a procedure that does

No, Bonita is mistaken. The standard provides a strong explicit
guarantee of what the behavior is when converting negative values to
unsigned type:

"... the value is converted by repeatedly adding ... one more than the
maximum value that can be represented in the new type until the value is
in the range of the new type." (6.3.1.3p2).

It's the other direction that's dangerous: conversion of an integer
value to a signed integer type that is not representable in that type
has undefined behavior.

Re: does a double cast to unsigned makes sense in any circumstance?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.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: does a double cast to unsigned makes sense in any circumstance?
Date: Sun, 16 Jan 2022 13:30:58 -0800
Organization: None to speak of
Lines: 19
Message-ID: <87y23fxt9p.fsf@nosuchdomain.example.com>
References: <86czl8kaew.fsf@levado.to> <sqvfed$rps$1@dont-email.me>
<8635lotrby.fsf@levado.to> <ss06le$h5n$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="edefa9a574b14021f379bca5fa220c53";
logging-data="26742"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX199ITurHKR2h0tdi0Z6ukwz"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:u3YFL1oL/qpbxOsPrYgN5J7MTsI=
sha1:qS0u0VYIVtK974tvAwzCVi5f7u8=
 by: Keith Thompson - Sun, 16 Jan 2022 21:30 UTC

James Kuyper <jameskuyper@alumni.caltech.edu> writes:
[...]
> "... the value is converted by repeatedly adding ... one more than the
> maximum value that can be represented in the new type until the value is
> in the range of the new type." (6.3.1.3p2).
>
> It's the other direction that's dangerous: conversion of an integer
> value to a signed integer type that is not representable in that type
> has undefined behavior.

No, converting an out-of-range integer value to a signed integer type
yields an implementation-defined result or raises an
implementation-defined signal. (C99 added the option of raising a
signal; in my opinion that was a bad idea.)

--
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: does a double cast to unsigned makes sense in any circumstance?

<ss2r36$e28$2@dont-email.me>

  copy mid

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

  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: does a double cast to unsigned makes sense in any circumstance?
Date: Sun, 16 Jan 2022 23:25:09 -0500
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <ss2r36$e28$2@dont-email.me>
References: <86czl8kaew.fsf@levado.to> <sqvfed$rps$1@dont-email.me>
<8635lotrby.fsf@levado.to> <ss06le$h5n$1@dont-email.me>
<87y23fxt9p.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 17 Jan 2022 04:25:10 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="fd482cf1ea24e5ecb0e212548399ef82";
logging-data="14408"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+3WdTGQSrvT49K4fo+91lTw6ka45ifpOc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:+9WV942vlczjkfL46pR8KbzS8jY=
In-Reply-To: <87y23fxt9p.fsf@nosuchdomain.example.com>
Content-Language: en-US
 by: James Kuyper - Mon, 17 Jan 2022 04:25 UTC

On 1/16/22 4:30 PM, Keith Thompson wrote:
> James Kuyper <jameskuyper@alumni.caltech.edu> writes:
> [...]
>> "... the value is converted by repeatedly adding ... one more than the
>> maximum value that can be represented in the new type until the value is
>> in the range of the new type." (6.3.1.3p2).
>>
>> It's the other direction that's dangerous: conversion of an integer
>> value to a signed integer type that is not representable in that type
>> has undefined behavior.
>
> No, converting an out-of-range integer value to a signed integer type
> yields an implementation-defined result or raises an
> implementation-defined signal. (C99 added the option of raising a
> signal; in my opinion that was a bad idea.)

Sorry - you're correct, and I actually knew that - but I was too tired
when I wrote that message.

Re: does a double cast to unsigned makes sense in any circumstance?

<86fspmr0u1.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!g347Oy2unFD3X1GTkuZnxA.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Date: Mon, 17 Jan 2022 09:41:42 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86fspmr0u1.fsf@levado.to>
References: <86czl8kaew.fsf@levado.to> <sqvfed$rps$1@dont-email.me>
<8635lotrby.fsf@levado.to> <ss06le$h5n$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="47194"; posting-host="g347Oy2unFD3X1GTkuZnxA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:zqwU4NxwlEeultVV+bcTOwmdBBA=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Mon, 17 Jan 2022 12:41 UTC

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

> On 1/15/22 8:14 PM, Meredith Montgomery wrote:
>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>
>>> Am 03.01.2022 um 18:15 schrieb Meredith Montgomery:
>>>> I've seen this somewhere or I wrote this some time in the past for some
>>>> reason and I can't see how this make sense any longer. In a procedure
>>>> to read a numeric string and turn it into a number, we need to convert
>>>> each char-digit to some kind of integer:
>>>> (uint64_t) (unsigned char) (s[pos] - '0');
>>>
>>> (s[pos] - '0') might me signed and without the cast to unsigned
>>> char it might be sign-extended to int64_4 before it is converted
>>> to uint64_t. ...
>
> He's right about it being signed - that's normally the case. It normally
> has the type `int`, except in the extremely unlikely case that CHAR_MAX
>> INT_MAX, in which case it will have the type `unsigned int`. However,
> int64_t comes into play only if it's typedef for `int`.
>
>>> ... But there are no guarantees when converting negative
>>> values to unsigneds.
>>
>> Really, no guarantees? So a procedure that does
>
> No, Bonita is mistaken. The standard provides a strong explicit
> guarantee of what the behavior is when converting negative values to
> unsigned type:
>
> "... the value is converted by repeatedly adding ... one more than the
> maximum value that can be represented in the new type until the value is
> in the range of the new type." (6.3.1.3p2).
>
> It's the other direction that's dangerous: conversion of an integer
> value to a signed integer type that is not representable in that type
> has undefined behavior.

That makes perfect sense. Thanks for the info. Very appreciated.

Re: does a double cast to unsigned makes sense in any circumstance?

<86a6fur0rh.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!g347Oy2unFD3X1GTkuZnxA.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Date: Mon, 17 Jan 2022 09:43:14 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86a6fur0rh.fsf@levado.to>
References: <86czl8kaew.fsf@levado.to> <sqvfed$rps$1@dont-email.me>
<8635lotrby.fsf@levado.to> <ss06le$h5n$1@dont-email.me>
<87y23fxt9p.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="47194"; posting-host="g347Oy2unFD3X1GTkuZnxA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:wusJC/ebH84kIX4U4IaOlAyx0xs=
 by: Meredith Montgomery - Mon, 17 Jan 2022 12:43 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> James Kuyper <jameskuyper@alumni.caltech.edu> writes:
> [...]
>> "... the value is converted by repeatedly adding ... one more than the
>> maximum value that can be represented in the new type until the value is
>> in the range of the new type." (6.3.1.3p2).
>>
>> It's the other direction that's dangerous: conversion of an integer
>> value to a signed integer type that is not representable in that type
>> has undefined behavior.
>
> No, converting an out-of-range integer value to a signed integer type
> yields an implementation-defined result or raises an
> implementation-defined signal. (C99 added the option of raising a
> signal; in my opinion that was a bad idea.)

Just curious --- why do you think a signal is a bad idea?

Re: does a double cast to unsigned makes sense in any circumstance?

<861r16r0p4.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!g347Oy2unFD3X1GTkuZnxA.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Date: Mon, 17 Jan 2022 09:44:39 -0300
Organization: Aioe.org NNTP Server
Message-ID: <861r16r0p4.fsf@levado.to>
References: <86czl8kaew.fsf@levado.to> <0gIAJ.2283$jW.2224@fx05.iad>
<86wnj0scpn.fsf@levado.to> <eWKEJ.204005$Wkjc.110862@fx35.iad>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="47194"; posting-host="g347Oy2unFD3X1GTkuZnxA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:pD6ZCBdz5fTjpZlwc+VveqpCAbE=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Mon, 17 Jan 2022 12:44 UTC

Richard Damon <Richard@Damon-Family.org> writes:

> On 1/15/22 8:15 PM, Meredith Montgomery wrote:
>> Richard Damon <Richard@Damon-Family.org> writes:
>>
>>> On 1/3/22 12:15 PM, Meredith Montgomery wrote:
>>>> I've seen this somewhere or I wrote this some time in the past for some
>>>> reason and I can't see how this make sense any longer. In a procedure
>>>> to read a numeric string and turn it into a number, we need to convert
>>>> each char-digit to some kind of integer:
>>>> (uint64_t) (unsigned char) (s[pos] - '0');
>>>> But the double cast here seems odd. I could have written this by
>>>> copying it from somewhere else. Today, what I would write is just
>>>> (uint64_t) (s[pos] - '0');
>>>> Am I making a mistake now? I can't anything wrong with this. Isn't
>>>> a
>>>> char just an int? I'm turning an int into an unsigned integer (of a
>>>> larger size).
>>>> Thank you!
>>>
>>> As others have said, it does change the behavior, but only if s[pos]
>>> might be less than '0', which means it holds something other than a
>>> digit, as the characters 0..9 are a required to be a consecutive
>>> increase sequence (which the code is likely counting on).
>>>
>>> If you know that s[pos] will always be > 0, then the double cast may
>>> produce faster code, as unless the compiler can also determine this,
>>> it may need to first sign extend to int, then zero extend to uint64_t,
>>> verse just zero extending to uint64_t.
>> What do you mean by ``zero extend''? Are you qualifying the verb
>> ``to
>> extend''? You lost me there. Thank you.
>
> When the processor loads the 8 bit character into the bottom of the
> register, it generally leaves the rest of the register alone.
>
> If Char is signed, and int is 32 bits, then the implementation can
> convert it to an int by extending the sign of the bottom byte into the
> rest of the register, and then to make it a unsigned 54 bit value, it
> needs to put zeros into the upper 32 bits of the register.
>
> By casting to unsigned character, then the implentation only needs to
> use an instruction that fills the upper 56 bits of the register to 0.
>
> Setting the upper bits of a register with a value is called 'extending'
>
> If it is copying the sign bit of the lower part of the register, it is
> called sign extending.
>
> If it is just fixing them to zero, it is called zero extending,
> because we are thinking of the always 0 'sign bits' that extend beyond
> the bits of the unsigned value.

Awesome information. Thank you so much.

Re: does a double cast to unsigned makes sense in any circumstance?

<86r196pm0y.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!g347Oy2unFD3X1GTkuZnxA.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Date: Mon, 17 Jan 2022 09:46:53 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86r196pm0y.fsf@levado.to>
References: <86czl8kaew.fsf@levado.to> <86y23gtmr0.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="47194"; posting-host="g347Oy2unFD3X1GTkuZnxA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:8EPatzEY87/pbzjeWPlZ2wtRvkY=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Mon, 17 Jan 2022 12:46 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

> Meredith Montgomery <mmontgomery@levado.to> writes:
>
>> I've seen this somewhere or I wrote this some time in the past for some
>> reason and I can't see how this make sense any longer. In a procedure
>> to read a numeric string and turn it into a number, we need to convert
>> each char-digit to some kind of integer:
>>
>> (uint64_t) (unsigned char) (s[pos] - '0');
>>
>> But the double cast here seems odd. I could have written this by
>> copying it from somewhere else. Today, what I would write is just
>>
>> (uint64_t) (s[pos] - '0');
>>
>> Am I making a mistake now? I can't anything wrong with this. Isn't a
>> char just an int? I'm turning an int into an unsigned integer (of a
>> larger size).
>
> The original context for the expression in question is this
> function:
>
>> [posted by Meredith Montgomery]
>>
>> #include <limits.h>
>> #include <inttypes.h>
>>
>> int scan_ulong(register char *s, register unsigned long *u)
>> {
>> register unsigned int pos;
>> register unsigned long r;
>> register unsigned long c;
>>
>> pos = 0; r = 0;
>>
>> for ( ;; ) {
>> c = (unsigned long) (unsigned char) (s[pos] - '0');
>> if (c < 10) {
>> if( ((ULONG_MAX - c) / 10) >= r)
>> r = r * 10 + c;
>> else return -1; /* lack of space */
>> ++pos; continue;
>> }
>> break;
>> }
>>
>> *u = r;
>> return pos;
>> }
>
> In this context, the casts are superfluous. Just write
>
> c = s[pos] - '0';
>
> and the right thing will happen, because the assignment to 'c'
> converts the value on the right hand side to 'unsigned long',
> and so takes care of any negative values.

Oh, interesting! Thanks! I did not think of that.

Re: does a double cast to unsigned makes sense in any circumstance?

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

  copy mid

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

  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: does a double cast to unsigned makes sense in any circumstance?
Date: Mon, 17 Jan 2022 13:59:46 -0800
Organization: None to speak of
Lines: 47
Message-ID: <87tue2xbu5.fsf@nosuchdomain.example.com>
References: <86czl8kaew.fsf@levado.to> <sqvfed$rps$1@dont-email.me>
<8635lotrby.fsf@levado.to> <ss06le$h5n$1@dont-email.me>
<87y23fxt9p.fsf@nosuchdomain.example.com> <86a6fur0rh.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="87cb8cebba4eb37201efcf1d755ef18c";
logging-data="12298"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+gfC4/gxMGzJYhMrYAAK/1"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:ZjEcjgz6l9oSJlhOoYizLs77HjU=
sha1:zBXyh4ijxGeWFkB85d8Xg23IwYs=
 by: Keith Thompson - Mon, 17 Jan 2022 21:59 UTC

Meredith Montgomery <mmontgomery@levado.to> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>> James Kuyper <jameskuyper@alumni.caltech.edu> writes:
>> [...]
>>> "... the value is converted by repeatedly adding ... one more than the
>>> maximum value that can be represented in the new type until the value is
>>> in the range of the new type." (6.3.1.3p2).
>>>
>>> It's the other direction that's dangerous: conversion of an integer
>>> value to a signed integer type that is not representable in that type
>>> has undefined behavior.
>>
>> No, converting an out-of-range integer value to a signed integer type
>> yields an implementation-defined result or raises an
>> implementation-defined signal. (C99 added the option of raising a
>> signal; in my opinion that was a bad idea.)
>
> Just curious --- why do you think a signal is a bad idea?

A signal isn't inherently a bad idea, particularly if portable code can
handle it. But the fact that the signal is implementation-defined makes
that impossible. (And freestanding implementations needn't support
<signal.h>.)

And I've never heard of an implementation that raises a signal on an out
of range conversion, so having that option has not turned out to be
useful.

To make it potentially useful, the standard could have required a
specific signal to be raised (say, SIGCONV, which could be an alias for
some other signal), and specified a predefined macro that tells you
which choice the implementation made.

Even more useful would be to require the signal (but that would break
existing code) or provide a mechanism to enable it (but that might be
too great a burden on existing implementations). But again, that would
leave freestanding implementations out in the cold.

Reliable handling of numeric overflow has always been difficult in C.
This feature seems like a single very small step in making it easier,
but without more complete support I think it would have been better to
leave it the way it was in C90.

--
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: does a double cast to unsigned makes sense in any circumstance?

<86bl05rc7i.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Date: Thu, 20 Jan 2022 19:37:21 -0800
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <86bl05rc7i.fsf@linuxsc.com>
References: <86czl8kaew.fsf@levado.to> <sqvdud$3tt$1@dont-email.me> <86bl0ctree.fsf@levado.to> <ss0605$e73$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="9bbd2bd2338bc444f9d0c408d9cb7c1c";
logging-data="6527"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183CRo0Q3gVUjYFAT0YXIyys+/RnPsX0EU="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:NgwcLTJPN6+ybo6NRToSdLeh+M4=
sha1:y/A+W/kSk9CtJPZQPCpSfF8vQcs=
 by: Tim Rentsch - Fri, 21 Jan 2022 03:37 UTC

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

> On 1/15/22 8:12 PM, Meredith Montgomery wrote:
> ...
>
>> Interesting. I got another question here. If s[pos] is always a char
>> and '0' is always a char, then s[pos] - '0' will never be greater than a
>> char. It might be negative. If it's negative and if I do
>
> Note that while members of the basic character set are required to be
> represented by non-negative values (6.2.5p3), members of the extended
> character set are not. If char is signed, they can be as low as
> CHAR_MIN, in which case subtracting '0' necessarily results in undefined
> behavior. [...]

No, it doesn't. Subtracting one character value from another can
give undefined behavior, but it doesn't have to, and indeed
usually cannot. The only circumstance where it can is when char
is signed and CHAR_MAX == INT_MAX.

Re: does a double cast to unsigned makes sense in any circumstance?

<3a6d2747-1a63-4ded-a568-3c05ca757827n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:20aa:: with SMTP id 10mr4795414qvd.40.1642786520890;
Fri, 21 Jan 2022 09:35:20 -0800 (PST)
X-Received: by 2002:a05:620a:a:: with SMTP id j10mr3465928qki.362.1642786520632;
Fri, 21 Jan 2022 09:35:20 -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: Fri, 21 Jan 2022 09:35:20 -0800 (PST)
In-Reply-To: <86bl05rc7i.fsf@linuxsc.com>
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: <86czl8kaew.fsf@levado.to> <sqvdud$3tt$1@dont-email.me>
<86bl0ctree.fsf@levado.to> <ss0605$e73$1@dont-email.me> <86bl05rc7i.fsf@linuxsc.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3a6d2747-1a63-4ded-a568-3c05ca757827n@googlegroups.com>
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
From: jameskuy...@alumni.caltech.edu (james...@alumni.caltech.edu)
Injection-Date: Fri, 21 Jan 2022 17:35:20 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 23
 by: james...@alumni.calt - Fri, 21 Jan 2022 17:35 UTC

On Thursday, January 20, 2022 at 10:37:33 PM UTC-5, Tim Rentsch wrote:
> James Kuyper <james...@alumni.caltech.edu> writes:
....
> > Note that while members of the basic character set are required to be
> > represented by non-negative values (6.2.5p3), members of the extended
> > character set are not. If char is signed, they can be as low as
> > CHAR_MIN, in which case subtracting '0' necessarily results in undefined
> > behavior. [...]

As Keith pointed out (and I had already conceded four days before your
message) that was a mistake on my part - the relevant clause says
"Otherwise, the new type is signed and the value cannot be represented in it;
either the result is implementation-defined or an implementation-defined
signal is raised." (6.3.1.3p3).

> No, it doesn't. Subtracting one character value from another can
> give undefined behavior, but it doesn't have to, and indeed
> usually cannot. The only circumstance where it can is when char
> is signed and CHAR_MAX == INT_MAX.

You're right - I was thinking about the possibility that CHAR_MAX == INT_MAX,
but I forgot to specify that this was a pre-condition for my claim that the
undefined behavior (which should instead have been a referrence to
6.3.1.3p3) was necessarily the result. Thank you for pointing this out.

Re: does a double cast to unsigned makes sense in any circumstance?

<86ee50pnwn.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Date: Fri, 21 Jan 2022 17:19:52 -0800
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <86ee50pnwn.fsf@linuxsc.com>
References: <86czl8kaew.fsf@levado.to> <sqvdud$3tt$1@dont-email.me> <86bl0ctree.fsf@levado.to> <ss0605$e73$1@dont-email.me> <86bl05rc7i.fsf@linuxsc.com> <3a6d2747-1a63-4ded-a568-3c05ca757827n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="434625eb2bdf5b21805d62a567edd212";
logging-data="31933"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+LrHwso5vAvHg8B0UfgrqHyWl3ke6lHT4="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:LX/uv42PGyuoyyIDoWD5mumg4sM=
sha1:pZuUQ74h/Hi6iDOF8HCkE6ZO3Ro=
 by: Tim Rentsch - Sat, 22 Jan 2022 01:19 UTC

"james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> writes:

> On Thursday, January 20, 2022 at 10:37:33 PM UTC-5, Tim Rentsch wrote:
>
>> James Kuyper <james...@alumni.caltech.edu> writes:
>
> ...
>
>>> Note that while members of the basic character set are
>>> required to be represented by non-negative values (6.2.5p3),
>>> members of the extended character set are not. If char is
>>> signed, they can be as low as CHAR_MIN, in which case
>>> subtracting '0' necessarily results in undefined behavior.
>>> [...]
>
> As Keith pointed out (and I had already conceded four days
> before your message) that was a mistake on my part - the
> relevant clause says "Otherwise, the new type is signed and the
> value cannot be represented in it; either the result is
> implementation-defined or an implementation-defined signal is
> raised." (6.3.1.3p3).

I noticed that, and saw Keith's response, and so chose not to
post a followup myself. But I wasn't saying anything about
converting back to a char, just about the subtraction.

>> No, it doesn't. Subtracting one character value from another can
>> give undefined behavior, but it doesn't have to, and indeed
>> usually cannot. The only circumstance where it can is when char
>> is signed and CHAR_MAX == INT_MAX.
>
> You're right - I was thinking about the possibility that
> CHAR_MAX == INT_MAX, but I forgot to specify that this was a
> pre-condition for my claim that the undefined behavior (which
> should instead have been a referrence to 6.3.1.3p3) was
> necessarily the result. Thank you for pointing this out.

I was confident you would understand the point once I mentioned
it. The followup was meant mainly for other readers who may
have been confused.

Re: does a double cast to unsigned makes sense in any circumstance?

<864k5n9wdw.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!SZor4ZqbvgPVVsWQ21e4cw.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: Re: does a double cast to unsigned makes sense in any circumstance?
Date: Fri, 28 Jan 2022 22:13:47 -0300
Organization: Aioe.org NNTP Server
Message-ID: <864k5n9wdw.fsf@levado.to>
References: <86czl8kaew.fsf@levado.to> <sqvfed$rps$1@dont-email.me>
<8635lotrby.fsf@levado.to> <ss06le$h5n$1@dont-email.me>
<87y23fxt9p.fsf@nosuchdomain.example.com> <86a6fur0rh.fsf@levado.to>
<87tue2xbu5.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="58030"; posting-host="SZor4ZqbvgPVVsWQ21e4cw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:15XGMMrAls4K4+/KDQDK6OWPEkE=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Sat, 29 Jan 2022 01:13 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Meredith Montgomery <mmontgomery@levado.to> writes:
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>> James Kuyper <jameskuyper@alumni.caltech.edu> writes:
>>> [...]
>>>> "... the value is converted by repeatedly adding ... one more than the
>>>> maximum value that can be represented in the new type until the value is
>>>> in the range of the new type." (6.3.1.3p2).
>>>>
>>>> It's the other direction that's dangerous: conversion of an integer
>>>> value to a signed integer type that is not representable in that type
>>>> has undefined behavior.
>>>
>>> No, converting an out-of-range integer value to a signed integer type
>>> yields an implementation-defined result or raises an
>>> implementation-defined signal. (C99 added the option of raising a
>>> signal; in my opinion that was a bad idea.)
>>
>> Just curious --- why do you think a signal is a bad idea?
>
> A signal isn't inherently a bad idea, particularly if portable code can
> handle it. But the fact that the signal is implementation-defined makes
> that impossible. (And freestanding implementations needn't support
> <signal.h>.)

What's a freestanding implementation?

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor