Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

You will never amount to much. -- Munich Schoolmaster, to Albert Einstein, age 10


devel / comp.lang.c / Re: on an analogy for verifying whether another digit fits (into an unsigned type)

SubjectAuthor
* on an analogy for verifying whether another digit fits (into an unsigned type)Meredith Montgomery
+* Re: on an analogy for verifying whether another digit fits (into anBart
|`* Re: on an analogy for verifying whether another digit fits (into an unsigned typMeredith Montgomery
| `* Re: on an analogy for verifying whether another digit fits (into an unsigned typBen Bacarisse
|  +* Re: on an analogy for verifying whether another digit fits (into an unsigned typScott Lurndal
|  |`* Re: on an analogy for verifying whether another digit fits (into an unsigned typBen Bacarisse
|  | `- Re: on an analogy for verifying whether another digit fits (into an unsigned typScott Lurndal
|  `* Re: on an analogy for verifying whether another digit fits (into an unsigned typMeredith Montgomery
|   `* Re: on an analogy for verifying whether another digit fits (into an unsigned typBen Bacarisse
|    `* Re: on an analogy for verifying whether another digit fits (into an unsigned typMeredith Montgomery
|     `- Re: on an analogy for verifying whether another digit fits (into an unsigned typBen Bacarisse
+* Re: on an analogy for verifying whether another digit fits (into anÖö Tiib
|`* Re: on an analogy for verifying whether another digit fits (into an unsigned typMeredith Montgomery
| `- Re: on an analogy for verifying whether another digit fits (into an unsigned typMeredith Montgomery
+* Re: on an analogy for verifying whether another digit fits (into anBonita Montero
|`* Re: on an analogy for verifying whether another digit fits (into anÖö Tiib
| `* Re: on an analogy for verifying whether another digit fits (into anBonita Montero
|  `* Re: on an analogy for verifying whether another digit fits (into anBonita Montero
|   `* Re: on an analogy for verifying whether another digit fits (into anBart
|    +* Re: on an analogy for verifying whether another digit fits (into anBonita Montero
|    |`* Re: on an analogy for verifying whether another digit fits (into anBonita Montero
|    | `- Re: on an analogy for verifying whether another digit fits (into anÖö Tiib
|    `* Re: on an analogy for verifying whether another digit fits (into an unsigned typScott Lurndal
|     `* Re: on an analogy for verifying whether another digit fits (into anBart
|      +* Re: on an analogy for verifying whether another digit fits (into an unsigned typScott Lurndal
|      |`* Re: on an analogy for verifying whether another digit fits (into anBart
|      | `* Re: on an analogy for verifying whether another digit fits (into an unsigned typBen Bacarisse
|      |  `* Re: on an analogy for verifying whether another digit fits (into anBart
|      |   `* Re: on an analogy for verifying whether another digit fits (into an unsigned typBen Bacarisse
|      |    `* Re: on an analogy for verifying whether another digit fits (into anBart
|      |     `- Re: on an analogy for verifying whether another digit fits (into anBart
|      `* Re: on an analogy for verifying whether another digit fits (into an unsigned typKeith Thompson
|       `* Re: on an analogy for verifying whether another digit fits (into anBart
|        +* Re: on an analogy for verifying whether another digit fits (into anLew Pitcher
|        |`- Re: on an analogy for verifying whether another digit fits (into anBart
|        +* Re: on an analogy for verifying whether another digit fits (into an unsigned typBen Bacarisse
|        |+* Re: on an analogy for verifying whether another digit fits (into anBart
|        ||+* Re: on an analogy for verifying whether another digit fits (into an unsigned typScott Lurndal
|        |||`* Re: on an analogy for verifying whether another digit fits (into an unsigned typKeith Thompson
|        ||| `- Re: on an analogy for verifying whether another digit fits (into an unsigned typScott Lurndal
|        ||+* Re: on an analogy for verifying whether another digit fits (into an unsigned typBen Bacarisse
|        |||`* Re: on an analogy for verifying whether another digit fits (into anBart
|        ||| `* Re: on an analogy for verifying whether another digit fits (into an unsigned typÖö Tiib
|        |||  `- Re: on an analogy for verifying whether another digit fits (into an unsigned typScott Lurndal
|        ||`- Re: on an analogy for verifying whether another digit fits (into an unsigned typKeith Thompson
|        |`- Re: on an analogy for verifying whether another digit fits (into anBart
|        +* Re: on an analogy for verifying whether another digit fits (into an unsigned typKeith Thompson
|        |`- Re: on an analogy for verifying whether another digit fits (into anBart
|        `* Re: on an analogy for verifying whether another digit fits (into an unsigned typScott Lurndal
|         `* Re: on an analogy for verifying whether another digit fits (into anBart
|          `* Re: on an analogy for verifying whether another digit fits (into an unsigned typKeith Thompson
|           `* Re: on an analogy for verifying whether another digit fits (into anBart
|            +- Re: on an analogy for verifying whether another digit fits (into an unsigned typKeith Thompson
|            `* Re: on an analogy for verifying whether another digit fits (into anManfred
|             `* Re: on an analogy for verifying whether another digit fits (into anBart
|              `- Re: on an analogy for verifying whether another digit fits (into anManfred
`* Re: on an analogy for verifying whether another digit fits (into an unsigned typTim Rentsch
 +* Re: on an analogy for verifying whether another digit fits (into anBonita Montero
 |`* Re: on an analogy for verifying whether another digit fits (into an unsigned typTim Rentsch
 | `* Re: on an analogy for verifying whether another digit fits (into anBonita Montero
 |  +* Re: on an analogy for verifying whether another digit fits (into an unsigned typScott Lurndal
 |  |`- Re: on an analogy for verifying whether another digit fits (into anBonita Montero
 |  `- Re: on an analogy for verifying whether another digit fits (into an unsigned typTim Rentsch
 `- Re: on an analogy for verifying whether another digit fits (into an unsigned typMeredith Montgomery

Pages:123
Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<ssccm5$mmo$1@dont-email.me>

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an
unsigned type)
Date: Thu, 20 Jan 2022 19:20:37 +0000
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <ssccm5$mmo$1@dont-email.me>
References: <86mtjws9cg.fsf@levado.to> <ss8g0e$8dv$1@dont-email.me>
<6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com>
<ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me>
<ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad>
<ss9u3b$jdr$1@dont-email.me> <X8%FJ.28$rU.26@fx34.iad>
<ssa342$rih$1@dont-email.me> <87tudz2his.fsf@bsb.me.uk>
<ssbc4i$9a0$1@dont-email.me> <87ilue2vda.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 20 Jan 2022 19:20:37 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d0672c75265e6b57e90f5faaf813e36f";
logging-data="23256"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+wCIfbmX37RINJWAVtQIy+UKDG6tCZYjg="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:MYJ1Q0oA14kKtGOndIOekR2cz1M=
In-Reply-To: <87ilue2vda.fsf@bsb.me.uk>
 by: Bart - Thu, 20 Jan 2022 19:20 UTC

On 20/01/2022 17:02, Ben Bacarisse wrote:
> Bart <bc@freeuk.com> writes:
>
>> On 20/01/2022 03:49, Ben Bacarisse wrote:
>>> Bart <bc@freeuk.com> writes:
>
>>>> * My parseull routine on Windows: 0.28/0.35 seconds (with/without
>>>> length)
>>>
>>> This one probably doesn't do the same job, so it's not a direct
>>> comparison.
>>
>> It was supposed to do the same job as BM's program: take a string
>> containing only digits and convert them while checking for overflows.
>
> Right. But it does not do the same job as the other functions you gave
> timings for /in the post I replied to/.

OK. Maybe you should ask Scott Lurndal why /he/ brought up strtoll().
The implication was they they did the same kind of thing, namely convert
a string of digits to an integer.

I suggested that among several reasons why a custom routine might be
used, was performance, even if they differ in features.

However, I've created a version of my routine which is more in line with
how strtoull etc work (but I don't know the full spec), shown below.

This version is still 50% faster than the fastest stroull routine on my
machine.

(One reason may be that it is hard-coded for base-10. If so, then that
is an argument for creating your own dedicated base-10 version.)

-----------------------------------------------
typedef unsigned long long u64;

u64 parseull(char* s, char** send) {
int length,neg=0;

while (*s==' ' || *s=='\t' ) ++s; // leading spaces
if (*s=='-') {neg=1; ++s;} // optional signs
else if (*s=='+') ++s;
while (*s=='0' && *(s+1)=='0') ++s; // leading zeros

length=0;
*send=s;

while (**send>='0' && **send<='9') ++(*send);
length=*send-s;
if (length==0) return -1; // u64.max on error
if (length>20) return -1;

if (length==20 && strncmp(s, "18446744073709551615",20)>0)
return -1;

u64 a=*s -'0';
while (--length) {a=a*10+*++s-'0';};
if (neg) return -a;
return a;
}

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<sscdb1$r1m$1@dont-email.me>

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an
unsigned type)
Date: Thu, 20 Jan 2022 19:31:45 +0000
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <sscdb1$r1m$1@dont-email.me>
References: <86mtjws9cg.fsf@levado.to> <ss8g0e$8dv$1@dont-email.me>
<6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com>
<ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me>
<ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad>
<ss9u3b$jdr$1@dont-email.me> <X8%FJ.28$rU.26@fx34.iad>
<ssa342$rih$1@dont-email.me> <87tudz2his.fsf@bsb.me.uk>
<ssbc4i$9a0$1@dont-email.me> <87ilue2vda.fsf@bsb.me.uk>
<ssccm5$mmo$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 20 Jan 2022 19:31:45 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d0672c75265e6b57e90f5faaf813e36f";
logging-data="27702"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18G8z1CHZ9MC//Pd9z1I0znLpdGp/U0K/E="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:3jF9GU5kT2KWUs8Lii6VQnm0im4=
In-Reply-To: <ssccm5$mmo$1@dont-email.me>
 by: Bart - Thu, 20 Jan 2022 19:31 UTC

On 20/01/2022 19:20, Bart wrote:

> -----------------------------------------------
>     typedef unsigned long long u64;
>
>     u64 parseull(char* s, char** send) {
>         int length,neg=0;
>
>         while (*s==' ' || *s=='\t' ) ++s;        // leading spaces
>         if (*s=='-') {neg=1; ++s;}               // optional signs
>         else if (*s=='+') ++s;
>         while (*s=='0' && *(s+1)=='0') ++s;      // leading zeros

That's not quite right, as it will leave 1 leading zero; better:

while (*s=='0' && (*(s+1)>='1' && *(s+1)<='9')) ++s;

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<86fsphrcsu.fsf@linuxsc.com>

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an unsigned type)
Date: Thu, 20 Jan 2022 19:24:33 -0800
Organization: A noiseless patient Spider
Lines: 69
Message-ID: <86fsphrcsu.fsf@linuxsc.com>
References: <86mtjws9cg.fsf@levado.to>
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="U2FsdGVkX1/QoMERLBlqvQnHmiVsJk8oTM4rQLnVA4c="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:1dbCOZ9G3urcPm6tcFA8x3cz3P4=
sha1:Wj7T8f899sam1ukNr3YBKN8DuIU=
 by: Tim Rentsch - Fri, 21 Jan 2022 03:24 UTC

Meredith Montgomery <mmontgomery@levado.to> writes:

> I've been trying to think of an analogy for the verification
>
> if( ((UINT64_MAX - c) / 10) >= r)
> r = r * 10 + c;
> else return -1; /* doesn't fit */
>
> in the procedure below. [...]

No analogy needed. The condition that needs to be
satisfied is

r * 10 + c <= UINT64_MAX

which is the same as

r * 10 <= UINT64_MAX - c

which is the same as

r <= (UINT64_MAX - c) / 10

which is the same as

(UINT64_MAX - c) / 10 >= r

giving the expression in the if() test. Done.

> (*) The procedure
>
> uint64_t array_to_uint64(char *s, uint64_t *u)
> {
> uint64_t pos;
> uint64_t r;
> uint64_t c;
>
> pos = 0; r = 0;
>
> for ( ;; ) {
> c = (uint64_t) (unsigned char) (s[pos] - '0');
> if (c < 10) {
> if( ((UINT64_MAX - c) / 10) >= r)
> r = r * 10 + c;
> else return -1; /* doesn't fit */
> ++pos; continue;
> }
> break;
> }
>
> *u = r;
> return pos;
> }

It's better to write the code so the funny division test
isn't needed:

uint64_t
array_to_uint64( char *s0, uint64_t *u ){
char *s = s0;
uint64_t r, d, nr;

for( r = 0; d = *s-'0', nr = r*10+d, d < 10; r = nr, s++ ){
if( r > nr ) return -1;
}

return *u = r, s-s0;
}

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<ssdm4d$2rg$1@dont-email.me>

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an
unsigned type)
Date: Fri, 21 Jan 2022 08:07:57 +0100
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <ssdm4d$2rg$1@dont-email.me>
References: <86mtjws9cg.fsf@levado.to> <86fsphrcsu.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 21 Jan 2022 07:07:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9be3970a2a11c48aaff7cf8c8e79d8c1";
logging-data="2928"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18vf3g2uavhwV8opQUv+imukawXgdB1x30="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:NSwcQ8Y5o3KT1EwD2wgmswWXHD8=
In-Reply-To: <86fsphrcsu.fsf@linuxsc.com>
Content-Language: de-DE
 by: Bonita Montero - Fri, 21 Jan 2022 07:07 UTC

Am 21.01.2022 um 04:24 schrieb Tim Rentsch:
> Meredith Montgomery <mmontgomery@levado.to> writes:
>
>> I've been trying to think of an analogy for the verification
>>
>> if( ((UINT64_MAX - c) / 10) >= r)
>> r = r * 10 + c;
>> else return -1; /* doesn't fit */
>>
>> in the procedure below. [...]
>
> No analogy needed. The condition that needs to be
> satisfied is
>
> r * 10 + c <= UINT64_MAX
>
> which is the same as
>
> r * 10 <= UINT64_MAX - c
>
> which is the same as
>
> r <= (UINT64_MAX - c) / 10
>
> which is the same as
>
> (UINT64_MAX - c) / 10 >= r
>
> giving the expression in the if() test. Done.
>

Doesn't help because c isn't a constant.

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<86r191p4rk.fsf@linuxsc.com>

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an unsigned type)
Date: Fri, 21 Jan 2022 06:01:03 -0800
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <86r191p4rk.fsf@linuxsc.com>
References: <86mtjws9cg.fsf@levado.to> <86fsphrcsu.fsf@linuxsc.com> <ssdm4d$2rg$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="20633"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mcYyoeD1OAqZSQvTkXepnU+rybwmwe2k="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:Wjwvx961oPPxZwdMpXww/U0e998=
sha1:F7RnoJpy0bPqwmnLZwoXyUqOKIY=
 by: Tim Rentsch - Fri, 21 Jan 2022 14:01 UTC

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

> Am 21.01.2022 um 04:24 schrieb Tim Rentsch:
>
>> Meredith Montgomery <mmontgomery@levado.to> writes:
>>
>>> I've been trying to think of an analogy for the verification
>>>
>>> if( ((UINT64_MAX - c) / 10) >= r)
>>> r = r * 10 + c;
>>> else return -1; /* doesn't fit */
>>>
>>> in the procedure below. [...]
>>
>> No analogy needed. The condition that needs to be
>> satisfied is
>>
>> r * 10 + c <= UINT64_MAX
>>
>> which is the same as
>>
>> r * 10 <= UINT64_MAX - c
>>
>> which is the same as
>>
>> r <= (UINT64_MAX - c) / 10
>>
>> which is the same as
>>
>> (UINT64_MAX - c) / 10 >= r
>>
>> giving the expression in the if() test. Done.
>
> Doesn't help because c isn't a constant.

It's hard to know what to say to such an obviously
inapplicable comment.

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<sseoot$ron$1@dont-email.me>

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an
unsigned type)
Date: Fri, 21 Jan 2022 17:59:10 +0100
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <sseoot$ron$1@dont-email.me>
References: <86mtjws9cg.fsf@levado.to> <86fsphrcsu.fsf@linuxsc.com>
<ssdm4d$2rg$1@dont-email.me> <86r191p4rk.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 21 Jan 2022 16:59:09 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9be3970a2a11c48aaff7cf8c8e79d8c1";
logging-data="28439"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19+TGnPk6z6zd5UnjrK+gBdDF87a/9SGCE="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:uv91RaSpjWNrbKI5MJ1on/aGF+c=
In-Reply-To: <86r191p4rk.fsf@linuxsc.com>
Content-Language: de-DE
 by: Bonita Montero - Fri, 21 Jan 2022 16:59 UTC

Am 21.01.2022 um 15:01 schrieb Tim Rentsch:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>
>> Am 21.01.2022 um 04:24 schrieb Tim Rentsch:
>>
>>> Meredith Montgomery <mmontgomery@levado.to> writes:
>>>
>>>> I've been trying to think of an analogy for the verification
>>>>
>>>> if( ((UINT64_MAX - c) / 10) >= r)
>>>> r = r * 10 + c;
>>>> else return -1; /* doesn't fit */
>>>>
>>>> in the procedure below. [...]
>>>
>>> No analogy needed. The condition that needs to be
>>> satisfied is
>>>
>>> r * 10 + c <= UINT64_MAX
>>>
>>> which is the same as
>>>
>>> r * 10 <= UINT64_MAX - c
>>>
>>> which is the same as
>>>
>>> r <= (UINT64_MAX - c) / 10
>>>
>>> which is the same as
>>>
>>> (UINT64_MAX - c) / 10 >= r
>>>
>>> giving the expression in the if() test. Done.
>>
>> Doesn't help because c isn't a constant.
>
> It's hard to know what to say to such an obviously
> inapplicable comment.

If your exchanges would result in a constant instead of a calucaltion
they would be favourable. But the overhead for your swapped calculation
is exactly the same and the code isn't more readable than before.

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<lfCGJ.309808$tX27.109231@fx04.ams4>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.uzoreto.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx04.ams4.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: on an analogy for verifying whether another digit fits (into an unsigned type)
Newsgroups: comp.lang.c
References: <86mtjws9cg.fsf@levado.to> <86fsphrcsu.fsf@linuxsc.com> <ssdm4d$2rg$1@dont-email.me> <86r191p4rk.fsf@linuxsc.com> <sseoot$ron$1@dont-email.me>
Lines: 55
Message-ID: <lfCGJ.309808$tX27.109231@fx04.ams4>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 21 Jan 2022 17:41:37 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 21 Jan 2022 17:41:37 GMT
X-Received-Bytes: 2240
 by: Scott Lurndal - Fri, 21 Jan 2022 17:41 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:
>Am 21.01.2022 um 15:01 schrieb Tim Rentsch:
>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>
>>> Am 21.01.2022 um 04:24 schrieb Tim Rentsch:
>>>
>>>> Meredith Montgomery <mmontgomery@levado.to> writes:
>>>>
>>>>> I've been trying to think of an analogy for the verification
>>>>>
>>>>> if( ((UINT64_MAX - c) / 10) >= r)
>>>>> r = r * 10 + c;
>>>>> else return -1; /* doesn't fit */
>>>>>
>>>>> in the procedure below. [...]
>>>>
>>>> No analogy needed. The condition that needs to be
>>>> satisfied is
>>>>
>>>> r * 10 + c <= UINT64_MAX
>>>>
>>>> which is the same as
>>>>
>>>> r * 10 <= UINT64_MAX - c
>>>>
>>>> which is the same as
>>>>
>>>> r <= (UINT64_MAX - c) / 10
>>>>
>>>> which is the same as
>>>>
>>>> (UINT64_MAX - c) / 10 >= r
>>>>
>>>> giving the expression in the if() test. Done.
>>>
>>> Doesn't help because c isn't a constant.
>>
>> It's hard to know what to say to such an obviously
>> inapplicable comment.
>
>If your exchanges would result in a constant instead of a calucaltion
>they would be favourable. But the overhead for your swapped calculation
>is exactly the same and the code isn't more readable than before.
>

Although the ordering can be significant from a security perspective,
consider this:

if (len > PAGE_SIZE - 2 - size)

vs. this:

if (size + len + 2 > PAGE_SIZE)

Which is better, and why?

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<ssetti$4v4$1@dont-email.me>

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an
unsigned type)
Date: Fri, 21 Jan 2022 19:26:59 +0100
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <ssetti$4v4$1@dont-email.me>
References: <86mtjws9cg.fsf@levado.to> <86fsphrcsu.fsf@linuxsc.com>
<ssdm4d$2rg$1@dont-email.me> <86r191p4rk.fsf@linuxsc.com>
<sseoot$ron$1@dont-email.me> <lfCGJ.309808$tX27.109231@fx04.ams4>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 21 Jan 2022 18:26:58 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9be3970a2a11c48aaff7cf8c8e79d8c1";
logging-data="5092"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BOZbzWaZhg2gbOkOpdWqSIb1w83s0hrQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:Brh7QcUZYI9XSLGKjG4Xhxf/UZI=
In-Reply-To: <lfCGJ.309808$tX27.109231@fx04.ams4>
Content-Language: de-DE
 by: Bonita Montero - Fri, 21 Jan 2022 18:26 UTC

Am 21.01.2022 um 18:41 schrieb Scott Lurndal:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>> Am 21.01.2022 um 15:01 schrieb Tim Rentsch:
>>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>>
>>>> Am 21.01.2022 um 04:24 schrieb Tim Rentsch:
>>>>
>>>>> Meredith Montgomery <mmontgomery@levado.to> writes:
>>>>>
>>>>>> I've been trying to think of an analogy for the verification
>>>>>>
>>>>>> if( ((UINT64_MAX - c) / 10) >= r)
>>>>>> r = r * 10 + c;
>>>>>> else return -1; /* doesn't fit */
>>>>>>
>>>>>> in the procedure below. [...]
>>>>>
>>>>> No analogy needed. The condition that needs to be
>>>>> satisfied is
>>>>>
>>>>> r * 10 + c <= UINT64_MAX
>>>>>
>>>>> which is the same as
>>>>>
>>>>> r * 10 <= UINT64_MAX - c
>>>>>
>>>>> which is the same as
>>>>>
>>>>> r <= (UINT64_MAX - c) / 10
>>>>>
>>>>> which is the same as
>>>>>
>>>>> (UINT64_MAX - c) / 10 >= r
>>>>>
>>>>> giving the expression in the if() test. Done.
>>>>
>>>> Doesn't help because c isn't a constant.
>>>
>>> It's hard to know what to say to such an obviously
>>> inapplicable comment.
>>
>> If your exchanges would result in a constant instead of a calucaltion
>> they would be favourable. But the overhead for your swapped calculation
>> is exactly the same and the code isn't more readable than before.
>>
>
> Although the ordering can be significant from a security perspective,
> consider this:
>
> if (len > PAGE_SIZE - 2 - size)
>
> vs. this:
>
> if (size + len + 2 > PAGE_SIZE)
>
> Which is better, and why?

Totally different discussion.

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<86ilucpo9d.fsf@linuxsc.com>

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an unsigned type)
Date: Fri, 21 Jan 2022 17:12:14 -0800
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <86ilucpo9d.fsf@linuxsc.com>
References: <86mtjws9cg.fsf@levado.to> <86fsphrcsu.fsf@linuxsc.com> <ssdm4d$2rg$1@dont-email.me> <86r191p4rk.fsf@linuxsc.com> <sseoot$ron$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="434625eb2bdf5b21805d62a567edd212";
logging-data="31933"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1teJQ4mpr6Xlkpo5L5fPjQ72mnUzY8qc="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:FnDgwyImJp2Z3S2jRcoN6V3DnQE=
sha1:KATBGpDMINDEvyUmeTDhVrdWbeY=
 by: Tim Rentsch - Sat, 22 Jan 2022 01:12 UTC

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

> Am 21.01.2022 um 15:01 schrieb Tim Rentsch:
>
>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>
>>> Am 21.01.2022 um 04:24 schrieb Tim Rentsch:
>>>
>>>> Meredith Montgomery <mmontgomery@levado.to> writes:
>>>>
>>>>> I've been trying to think of an analogy for the verification
>>>>>
>>>>> if( ((UINT64_MAX - c) / 10) >= r)
>>>>> r = r * 10 + c;
>>>>> else return -1; /* doesn't fit */
>>>>>
>>>>> in the procedure below. [...]
>>>>
>>>> No analogy needed. The condition that needs to be
>>>> satisfied is
>>>>
>>>> r * 10 + c <= UINT64_MAX
>>>>
>>>> which is the same as
>>>>
>>>> r * 10 <= UINT64_MAX - c
>>>>
>>>> which is the same as
>>>>
>>>> r <= (UINT64_MAX - c) / 10
>>>>
>>>> which is the same as
>>>>
>>>> (UINT64_MAX - c) / 10 >= r
>>>>
>>>> giving the expression in the if() test. Done.
>>>
>>> Doesn't help because c isn't a constant.
>>
>> It's hard to know what to say to such an obviously
>> inapplicable comment.
>
> If your exchanges would result in a constant instead of a
> calucaltion they would be favourable. But the overhead for
> your swapped calculation is exactly the same and the code isn't
> more readable than before.

Apparently you don't understand that your comment has no bearing
on what I was talking about.

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

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

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an unsigned type)
Date: Sun, 23 Jan 2022 14:26:26 -0800
Organization: None to speak of
Lines: 28
Message-ID: <87pmoixf59.fsf@nosuchdomain.example.com>
References: <86mtjws9cg.fsf@levado.to> <ss8g0e$8dv$1@dont-email.me>
<6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com>
<ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me>
<ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad>
<ss9u3b$jdr$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="bf212cab00378f73488330ba3dd56683";
logging-data="3010"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eIok5xxMfdP4MXmIb4EVr"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:wBhc0sXOirUNI8xyKH9qKkZ4LxI=
sha1:dnShaN/nbtUnfiPFM5cIgsWN3q8=
 by: Keith Thompson - Sun, 23 Jan 2022 22:26 UTC

Bart <bc@freeuk.com> writes:
> On 19/01/2022 18:46, Scott Lurndal wrote:
>> Bart <bc@freeuk.com> writes:
>>> On 19/01/2022 17:02, Bonita Montero wrote:
>>> Complicated. I used the simpler **C** code below. It's runtime was 10%
>>> slower than the C++ (that is, elapsed time of the 10,000 outer loop for
>>> both).
>> I just use strtoll. Why reinvent the wheel?
>
> It needs to be stroull() for this purpose, which is more elusive (gcc
> has it on Windows, but the two other compilers I have don't),

gcc does not provide strtoll() or strtoull(). Both are provided by the
library, not by the compiler. (And both were introduced in C99, so I'd
be at least mildly surprised by an implementation that provides one
but not the other.)

I know you're tired of people pointing out that the compiler (gcc
in this case) does not provide library functions. The solution is
for you to stop making that mistake. Or should I assume you enjoy
these arguments?

[...]

--
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: on an analogy for verifying whether another digit fits (into an unsigned type)

<sskqvb$im7$1@dont-email.me>

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an
unsigned type)
Date: Mon, 24 Jan 2022 00:13:32 +0000
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <sskqvb$im7$1@dont-email.me>
References: <86mtjws9cg.fsf@levado.to> <ss8g0e$8dv$1@dont-email.me>
<6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com>
<ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me>
<ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad>
<ss9u3b$jdr$1@dont-email.me> <87pmoixf59.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jan 2022 00:13:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ffd3f67a34ea05229c22240f8aaaf2f6";
logging-data="19143"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18j0ntfdnjsvlB5wNJ5wZJxGe0+8X7RDbY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:f4pIv7KAnhpNjvXNUNGKlPvWEWc=
In-Reply-To: <87pmoixf59.fsf@nosuchdomain.example.com>
 by: Bart - Mon, 24 Jan 2022 00:13 UTC

On 23/01/2022 22:26, Keith Thompson wrote:
> Bart <bc@freeuk.com> writes:
>> On 19/01/2022 18:46, Scott Lurndal wrote:
>>> Bart <bc@freeuk.com> writes:
>>>> On 19/01/2022 17:02, Bonita Montero wrote:
>>>> Complicated. I used the simpler **C** code below. It's runtime was 10%
>>>> slower than the C++ (that is, elapsed time of the 10,000 outer loop for
>>>> both).
>>> I just use strtoll. Why reinvent the wheel?
>>
>> It needs to be stroull() for this purpose, which is more elusive (gcc
>> has it on Windows, but the two other compilers I have don't),
>
> gcc does not provide strtoll() or strtoull(). Both are provided by the
> library, not by the compiler. (And both were introduced in C99, so I'd
> be at least mildly surprised by an implementation that provides one
> but not the other.)
>
> I know you're tired of people pointing out that the compiler (gcc
> in this case) does not provide library functions. The solution is
> for you to stop making that mistake. Or should I assume you enjoy
> these arguments?

gcc/tdm compiles programs using strtoull.

bcc/tcc fail with a link error, unless I include this line:

#define strtoull _strtoui64

but then gcc will complain about it.

Actually why that is the case, I don't know, don't care, and probably no
else cares who just installs a 'bundle' without wanting to trace and
check the provenance of each library function that it comes with.

The above is enough for me to think twice about using strtoull in a project.

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<sskseu$if4$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.lang.c
Subject: Re: on an analogy for verifying whether another digit fits (into an
unsigned type)
Date: Mon, 24 Jan 2022 00:38:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <sskseu$if4$1@dont-email.me>
References: <86mtjws9cg.fsf@levado.to> <ss8g0e$8dv$1@dont-email.me>
<6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com>
<ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me>
<ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad>
<ss9u3b$jdr$1@dont-email.me> <87pmoixf59.fsf@nosuchdomain.example.com>
<sskqvb$im7$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 24 Jan 2022 00:38:54 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b4fa0317202fe55be66421c1f502f69c";
logging-data="18916"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1++geW2ijpiYMn0tyjiwkH1ecWGNngV5ME="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:QJFDuzjPjIraeV9k6IG3qsxzo/M=
 by: Lew Pitcher - Mon, 24 Jan 2022 00:38 UTC

On Mon, 24 Jan 2022 00:13:32 +0000, Bart wrote:

> On 23/01/2022 22:26, Keith Thompson wrote:
>> Bart <bc@freeuk.com> writes:
>>> On 19/01/2022 18:46, Scott Lurndal wrote:
>>>> Bart <bc@freeuk.com> writes:
>>>>> On 19/01/2022 17:02, Bonita Montero wrote:
>>>>> Complicated. I used the simpler **C** code below. It's runtime was 10%
>>>>> slower than the C++ (that is, elapsed time of the 10,000 outer loop for
>>>>> both).
>>>> I just use strtoll. Why reinvent the wheel?
>>>
>>> It needs to be stroull() for this purpose, which is more elusive (gcc
>>> has it on Windows, but the two other compilers I have don't),
>>
>> gcc does not provide strtoll() or strtoull(). Both are provided by the
>> library, not by the compiler. (And both were introduced in C99, so I'd
>> be at least mildly surprised by an implementation that provides one
>> but not the other.)
>>
>> I know you're tired of people pointing out that the compiler (gcc
>> in this case) does not provide library functions. The solution is
>> for you to stop making that mistake. Or should I assume you enjoy
>> these arguments?
>
> gcc/tdm compiles programs using strtoull.
>
> bcc/tcc fail with a link error, unless I include this line:
>
> #define strtoull _strtoui64
>
> but then gcc will complain about it.

Countless generations of programmers have found a sensible way to handle such
conflicts by using conditional compilation.

strtoull() has been defined as being part of the C99 standard library, and
before that, part of the POSIX.1-2001 and POSIX.1-2001 Unix standard libraries.
A simple macro test of the value of __STDC_VERSION__, and setting of the appropriate
pre-C99 macros should be all that is necessary to properly access strtoull().

Something like
#if (__STDC_VERSION__ < 199901l)
//do whatever it takes to properly define strtoull() for this platform
#endif

(note, the above "do whatever" might include such things as testing macros
to determine the platform and take appropriate action, as in
#ifdef WIN32
#define strtoull _strtoui64
#endif
or defining macros to force platform-specific libraries, like
#define _SVID_SOURCE

[snip]
> The above is enough for me to think twice about using strtoull in a project.

Your loss, I guess.

--
Lew Pitcher
"In Skills, We Trust"

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<ssku8l$2uq$1@dont-email.me>

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an
unsigned type)
Date: Mon, 24 Jan 2022 01:09:42 +0000
Organization: A noiseless patient Spider
Lines: 73
Message-ID: <ssku8l$2uq$1@dont-email.me>
References: <86mtjws9cg.fsf@levado.to> <ss8g0e$8dv$1@dont-email.me>
<6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com>
<ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me>
<ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad>
<ss9u3b$jdr$1@dont-email.me> <87pmoixf59.fsf@nosuchdomain.example.com>
<sskqvb$im7$1@dont-email.me> <sskseu$if4$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jan 2022 01:09:41 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ffd3f67a34ea05229c22240f8aaaf2f6";
logging-data="3034"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18UeTMO2IzKkQHZ37qZDxS8E83Wfq1vwL4="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:rpAwINwk3N4ghmwA2w2lehvxqAQ=
In-Reply-To: <sskseu$if4$1@dont-email.me>
 by: Bart - Mon, 24 Jan 2022 01:09 UTC

On 24/01/2022 00:38, Lew Pitcher wrote:
> On Mon, 24 Jan 2022 00:13:32 +0000, Bart wrote:
>
>> On 23/01/2022 22:26, Keith Thompson wrote:
>>> Bart <bc@freeuk.com> writes:
>>>> On 19/01/2022 18:46, Scott Lurndal wrote:
>>>>> Bart <bc@freeuk.com> writes:
>>>>>> On 19/01/2022 17:02, Bonita Montero wrote:
>>>>>> Complicated. I used the simpler **C** code below. It's runtime was 10%
>>>>>> slower than the C++ (that is, elapsed time of the 10,000 outer loop for
>>>>>> both).
>>>>> I just use strtoll. Why reinvent the wheel?
>>>>
>>>> It needs to be stroull() for this purpose, which is more elusive (gcc
>>>> has it on Windows, but the two other compilers I have don't),
>>>
>>> gcc does not provide strtoll() or strtoull(). Both are provided by the
>>> library, not by the compiler. (And both were introduced in C99, so I'd
>>> be at least mildly surprised by an implementation that provides one
>>> but not the other.)
>>>
>>> I know you're tired of people pointing out that the compiler (gcc
>>> in this case) does not provide library functions. The solution is
>>> for you to stop making that mistake. Or should I assume you enjoy
>>> these arguments?
>>
>> gcc/tdm compiles programs using strtoull.
>>
>> bcc/tcc fail with a link error, unless I include this line:
>>
>> #define strtoull _strtoui64
>>
>> but then gcc will complain about it.
>
> Countless generations of programmers have found a sensible way to handle such
> conflicts by using conditional compilation.
>
> strtoull() has been defined as being part of the C99 standard library, and
> before that, part of the POSIX.1-2001 and POSIX.1-2001 Unix standard libraries.
> A simple macro test of the value of __STDC_VERSION__, and setting of the appropriate
> pre-C99 macros should be all that is necessary to properly access strtoull().
>
> Something like
> #if (__STDC_VERSION__ < 199901l)
> //do whatever it takes to properly define strtoull() for this platform
> #endif
>
> (note, the above "do whatever" might include such things as testing macros
> to determine the platform and take appropriate action, as in
> #ifdef WIN32
> #define strtoull _strtoui64
> #endif
> or defining macros to force platform-specific libraries, like
> #define _SVID_SOURCE

If you're an implementer creating headers for a C compiler, then you
should just declare then properly.

I just have in mine; it took a minute or so (after previously finding
out that MS uses that different naming). But I can't do it for tcc or
any other compiler that might have an issue.

And if you're not an implementer, then that's a lot of clutter to go
into your application's headers just to pander for one or two compilers.

It's the sort of think I absolutely hate when poking arond application
headers, trying to figure why it doesn't work, because it's
special-casing some specific compilers, which will then exclude mine.

You might as well just implement a suitable function, then it'll run
anywhere, might be faster as I found, and could be made with a sweeter
interface.

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

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

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an unsigned type)
Date: Mon, 24 Jan 2022 01:15:53 +0000
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <87wniq0w8m.fsf@bsb.me.uk>
References: <86mtjws9cg.fsf@levado.to> <ss8g0e$8dv$1@dont-email.me>
<6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com>
<ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me>
<ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad>
<ss9u3b$jdr$1@dont-email.me> <87pmoixf59.fsf@nosuchdomain.example.com>
<sskqvb$im7$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="af9c25630be9b14368cf3170ae6cca15";
logging-data="4957"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18uMxGXuNhzw9LyPzXAIR9ZMBquG+IZZD0="
Cancel-Lock: sha1:4pvZJt3Cr+NA1Kmmtrg2w4U/bAI=
sha1:jgeFP/QIHaboFuSiNRTcCurhYwM=
X-BSB-Auth: 1.c960acd56ea4d96fa799.20220124011553GMT.87wniq0w8m.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 24 Jan 2022 01:15 UTC

Bart <bc@freeuk.com> writes:

> On 23/01/2022 22:26, Keith Thompson wrote:
>> Bart <bc@freeuk.com> writes:
>>> On 19/01/2022 18:46, Scott Lurndal wrote:
>>>> Bart <bc@freeuk.com> writes:
>>>>> On 19/01/2022 17:02, Bonita Montero wrote:
>>>>> Complicated. I used the simpler **C** code below. It's runtime was 10%
>>>>> slower than the C++ (that is, elapsed time of the 10,000 outer loop for
>>>>> both).
>>>> I just use strtoll. Why reinvent the wheel?
>>>
>>> It needs to be stroull() for this purpose, which is more elusive (gcc
>>> has it on Windows, but the two other compilers I have don't),
>> gcc does not provide strtoll() or strtoull(). Both are provided by the
>> library, not by the compiler. (And both were introduced in C99, so I'd
>> be at least mildly surprised by an implementation that provides one
>> but not the other.)
>> I know you're tired of people pointing out that the compiler (gcc
>> in this case) does not provide library functions. The solution is
>> for you to stop making that mistake. Or should I assume you enjoy
>> these arguments?
>
> gcc/tdm compiles programs using strtoull.
>
> bcc/tcc fail with a link error,

My tcc-based C installation handles it fine. That's because, as you
must know, it's not a compiler issue.

> unless I include this line:
>
> #define strtoull _strtoui64

Which, of course, means "unless I don't use strtoull".

> but then gcc will complain about it.
>
> Actually why that is the case, I don't know, don't care, and probably
> no else cares who just installs a 'bundle' without wanting to trace
> and check the provenance of each library function that it comes with.

I'd hope it's rare to not want to know what's going on.

> The above is enough for me to think twice about using strtoull in a
> project.

If your code must work with non-standard C implementations, then there
might well be a whole raft of things you should avoid. But since you
seem to use C a lot, wouldn't it be better either to try to fix your tcc
installation or to simply uninstall it?

--
Ben.

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

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

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an unsigned type)
Date: Sun, 23 Jan 2022 17:38:25 -0800
Organization: None to speak of
Lines: 46
Message-ID: <875yq9q5f2.fsf@nosuchdomain.example.com>
References: <86mtjws9cg.fsf@levado.to> <ss8g0e$8dv$1@dont-email.me>
<6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com>
<ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me>
<ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad>
<ss9u3b$jdr$1@dont-email.me> <87pmoixf59.fsf@nosuchdomain.example.com>
<sskqvb$im7$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="94b3a3008f708f7b40cdf3a125e51cf3";
logging-data="10254"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+t9XzT3xIdSoY5DUpX5C42"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:OOKkpzzjmUYimGvG4G3dyOKNrok=
sha1:nLYTTEENUMnzX/DY1p+c13S7Vx4=
 by: Keith Thompson - Mon, 24 Jan 2022 01:38 UTC

Bart <bc@freeuk.com> writes:
> On 23/01/2022 22:26, Keith Thompson wrote:
>> Bart <bc@freeuk.com> writes:
>>> On 19/01/2022 18:46, Scott Lurndal wrote:
>>>> Bart <bc@freeuk.com> writes:
>>>>> On 19/01/2022 17:02, Bonita Montero wrote:
>>>>> Complicated. I used the simpler **C** code below. It's runtime was 10%
>>>>> slower than the C++ (that is, elapsed time of the 10,000 outer loop for
>>>>> both).
>>>> I just use strtoll. Why reinvent the wheel?
>>>
>>> It needs to be stroull() for this purpose, which is more elusive (gcc
>>> has it on Windows, but the two other compilers I have don't),
>> gcc does not provide strtoll() or strtoull(). Both are provided by
>> the
>> library, not by the compiler. (And both were introduced in C99, so I'd
>> be at least mildly surprised by an implementation that provides one
>> but not the other.)
>> I know you're tired of people pointing out that the compiler (gcc
>> in this case) does not provide library functions. The solution is
>> for you to stop making that mistake. Or should I assume you enjoy
>> these arguments?
>
> gcc/tdm compiles programs using strtoull.
>
> bcc/tcc fail with a link error, unless I include this line:
>
> #define strtoull _strtoui64
>
> but then gcc will complain about it.
>
> Actually why that is the case, I don't know, don't care, and probably
> no else cares who just installs a 'bundle' without wanting to trace
> and check the provenance of each library function that it comes with.
>
> The above is enough for me to think twice about using strtoull in a project.

It's obvious that you just enjoy the arguments that result when you
pretend to misunderstand the difference between a compiler and an
implementation and are not interested in helping anyone else understand
it. I'll try to adjust my future responses accordingly.

--
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: on an analogy for verifying whether another digit fits (into an unsigned type)

<ssm23g$q5s$1@dont-email.me>

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an
unsigned type)
Date: Mon, 24 Jan 2022 11:21:20 +0000
Organization: A noiseless patient Spider
Lines: 98
Message-ID: <ssm23g$q5s$1@dont-email.me>
References: <86mtjws9cg.fsf@levado.to> <ss8g0e$8dv$1@dont-email.me>
<6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com>
<ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me>
<ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad>
<ss9u3b$jdr$1@dont-email.me> <87pmoixf59.fsf@nosuchdomain.example.com>
<sskqvb$im7$1@dont-email.me> <87wniq0w8m.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jan 2022 11:21:20 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ffd3f67a34ea05229c22240f8aaaf2f6";
logging-data="26812"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180vHHFlz158zwsJ8kVcrV779F0gCo/Ud8="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:bQ4uqzmE+mDP3OwXkwBdZLIDxws=
In-Reply-To: <87wniq0w8m.fsf@bsb.me.uk>
 by: Bart - Mon, 24 Jan 2022 11:21 UTC

On 24/01/2022 01:15, Ben Bacarisse wrote:
> Bart <bc@freeuk.com> writes:
>
>> On 23/01/2022 22:26, Keith Thompson wrote:
>>> Bart <bc@freeuk.com> writes:
>>>> On 19/01/2022 18:46, Scott Lurndal wrote:
>>>>> Bart <bc@freeuk.com> writes:
>>>>>> On 19/01/2022 17:02, Bonita Montero wrote:
>>>>>> Complicated. I used the simpler **C** code below. It's runtime was 10%
>>>>>> slower than the C++ (that is, elapsed time of the 10,000 outer loop for
>>>>>> both).
>>>>> I just use strtoll. Why reinvent the wheel?
>>>>
>>>> It needs to be stroull() for this purpose, which is more elusive (gcc
>>>> has it on Windows, but the two other compilers I have don't),
>>> gcc does not provide strtoll() or strtoull(). Both are provided by the
>>> library, not by the compiler. (And both were introduced in C99, so I'd
>>> be at least mildly surprised by an implementation that provides one
>>> but not the other.)
>>> I know you're tired of people pointing out that the compiler (gcc
>>> in this case) does not provide library functions. The solution is
>>> for you to stop making that mistake. Or should I assume you enjoy
>>> these arguments?
>>
>> gcc/tdm compiles programs using strtoull.
>>
>> bcc/tcc fail with a link error,
>
> My tcc-based C installation handles it fine. That's because, as you
> must know, it's not a compiler issue.

c:\c>type c.c
#include <stdio.h>
#include <stdlib.h>

int main(void) {
char* p;
printf("%llu\n", strtoull("1234", &p, 10));
}

c:\c>tcc c.c
tcc: error: undefined symbol 'strtoull'

c:\c>tcc -c c.c

c:\c>tcc -v
tcc version 0.9.27 (x86_64 Windows)

It looks like a link issue with tcc to me. As I said this was on
Windows. tcc appears to use msvcrt.dll, because when I add that define,
and look at the resulting exe, it says:

Name: msvcrt.dll
Import Addr RVA: 2038
Import: 20e3 0 _strtoui64
Import: 20f0 0 printf
Import: 20f9 0 __set_app_type
....

Maybe some people spend at lot of time telling their compilers exactly
which libraries to use for standard functions of C; I just use the
supplied compiler or driver program.

Since all C compilers that I've used will do the whole job of source ->
binary just by invoking that front end.

So, what version of tcc do you have, and what special thing do you have
to do to make it work?

If you're on Linux, that doesn't count as the standard library is
unlikely to use MS's _strtoui64 name for that function.

This is what I originally said:

"...(gcc has it on Windows, but the two other compilers I have don't)"

>> unless I include this line:
>>
>> #define strtoull _strtoui64
>
> Which, of course, means "unless I don't use strtoull".

It's better not to. If I were to post code anywhere that used it, then
at least some people trying it wouldn't be able to build it. And I'm not
having /my/ code full of those implementation-specific conditional
blocks that I despise.

For the same reason, I tend not to write shared code that uses '$' in
identifiers, because tcc doesn't support it.

> If your code must work with non-standard C implementations, then there
> might well be a whole raft of things you should avoid. But since you
> seem to use C a lot, wouldn't it be better either to try to fix your tcc
> installation or to simply uninstall it?

What do you mean by fix? Fixing my tcc doesn't help people compiling my
code unless everybody fixes theirs too.

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<ssm256$q5s$2@dont-email.me>

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an
unsigned type)
Date: Mon, 24 Jan 2022 11:22:14 +0000
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <ssm256$q5s$2@dont-email.me>
References: <86mtjws9cg.fsf@levado.to> <ss8g0e$8dv$1@dont-email.me>
<6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com>
<ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me>
<ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad>
<ss9u3b$jdr$1@dont-email.me> <87pmoixf59.fsf@nosuchdomain.example.com>
<sskqvb$im7$1@dont-email.me> <875yq9q5f2.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jan 2022 11:22:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ffd3f67a34ea05229c22240f8aaaf2f6";
logging-data="26812"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+6c2IOSf/je77J9Ai7KhkdoUDHBmZsziw="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:KcUkDT/Yqs5juEYwQLSyiZDjgWU=
In-Reply-To: <875yq9q5f2.fsf@nosuchdomain.example.com>
 by: Bart - Mon, 24 Jan 2022 11:22 UTC

On 24/01/2022 01:38, Keith Thompson wrote:
> Bart <bc@freeuk.com> writes:

> It's obvious that you just enjoy the arguments that result when you
> pretend to misunderstand the difference between a compiler and an
> implementation and are not interested in helping anyone else understand
> it. I'll try to adjust my future responses accordingly.

It's not me bringing this up each time. It's you.

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<ssm3s2$665$1@dont-email.me>

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an
unsigned type)
Date: Mon, 24 Jan 2022 11:51:31 +0000
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <ssm3s2$665$1@dont-email.me>
References: <86mtjws9cg.fsf@levado.to> <ss8g0e$8dv$1@dont-email.me>
<6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com>
<ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me>
<ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad>
<ss9u3b$jdr$1@dont-email.me> <87pmoixf59.fsf@nosuchdomain.example.com>
<sskqvb$im7$1@dont-email.me> <87wniq0w8m.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jan 2022 11:51:30 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ffd3f67a34ea05229c22240f8aaaf2f6";
logging-data="6341"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18rSN3SrzxFELPlfKIrk0djuYshtFmF4Es="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:SlEQydifAUUpKBhwxUqs4qYH7Rs=
In-Reply-To: <87wniq0w8m.fsf@bsb.me.uk>
 by: Bart - Mon, 24 Jan 2022 11:51 UTC

On 24/01/2022 01:15, Ben Bacarisse wrote:
> Bart <bc@freeuk.com> writes:
>
>> On 23/01/2022 22:26, Keith Thompson wrote:
>>> Bart <bc@freeuk.com> writes:
>>>> On 19/01/2022 18:46, Scott Lurndal wrote:
>>>>> Bart <bc@freeuk.com> writes:
>>>>>> On 19/01/2022 17:02, Bonita Montero wrote:
>>>>>> Complicated. I used the simpler **C** code below. It's runtime was 10%
>>>>>> slower than the C++ (that is, elapsed time of the 10,000 outer loop for
>>>>>> both).
>>>>> I just use strtoll. Why reinvent the wheel?
>>>>
>>>> It needs to be stroull() for this purpose, which is more elusive (gcc
>>>> has it on Windows, but the two other compilers I have don't),
>>> gcc does not provide strtoll() or strtoull(). Both are provided by the
>>> library, not by the compiler. (And both were introduced in C99, so I'd
>>> be at least mildly surprised by an implementation that provides one
>>> but not the other.)
>>> I know you're tired of people pointing out that the compiler (gcc
>>> in this case) does not provide library functions. The solution is
>>> for you to stop making that mistake. Or should I assume you enjoy
>>> these arguments?
>>
>> gcc/tdm compiles programs using strtoull.
>>
>> bcc/tcc fail with a link error,
>
> My tcc-based C installation handles it fine. That's because, as you
> must know, it's not a compiler issue.
>
>> unless I include this line:
>>
>> #define strtoull _strtoui64
>
> Which, of course, means "unless I don't use strtoull".
>
>> but then gcc will complain about it.
>>
>> Actually why that is the case, I don't know, don't care, and probably
>> no else cares who just installs a 'bundle' without wanting to trace
>> and check the provenance of each library function that it comes with.
>
> I'd hope it's rare to not want to know what's going on.

I know what's going on here; but I can't do anything about it.

Inside my tcc's stdlib.h is this:

unsigned long long __cdecl strtoull(const char* __restrict__, char**
__restrict__, int);

Tha's identical to that from gcc/tdm's stdlib.h, but minus a
__MINGW_EXTENSION macro at the start.

However my gcc/tdm manages to associate that with an actual function
somewhere called 'strtoull'; tcc won't be able to do that if it only
makes use of msvcrt.dll.

Clearly no one ever tested strtoull on Windows tcc; neither did I on my
bcc; I copied the strtoull declaration from lccwin's stdlib.h; that one
uses its own implementation of the function.

(If I change tcc's stdlib to use _strtoui64 and add that define, then it
will work. But so what? I'm only changing my personal copy.)

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<sWzHJ.11681$1_.11496@fx37.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.uzoreto.com!npeer.as286.net!npeer-ng0.as286.net!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx37.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: on an analogy for verifying whether another digit fits (into an unsigned type)
Newsgroups: comp.lang.c
References: <86mtjws9cg.fsf@levado.to> <ss8g0e$8dv$1@dont-email.me> <6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com> <ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me> <ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad> <ss9u3b$jdr$1@dont-email.me> <87pmoixf59.fsf@nosuchdomain.example.com> <sskqvb$im7$1@dont-email.me>
Lines: 31
Message-ID: <sWzHJ.11681$1_.11496@fx37.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Mon, 24 Jan 2022 15:51:52 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 24 Jan 2022 15:51:52 GMT
X-Received-Bytes: 2322
 by: Scott Lurndal - Mon, 24 Jan 2022 15:51 UTC

Bart <bc@freeuk.com> writes:
>On 23/01/2022 22:26, Keith Thompson wrote:
>> Bart <bc@freeuk.com> writes:
>>> On 19/01/2022 18:46, Scott Lurndal wrote:
>>>> Bart <bc@freeuk.com> writes:
>>>>> On 19/01/2022 17:02, Bonita Montero wrote:
>>>>> Complicated. I used the simpler **C** code below. It's runtime was 10%
>>>>> slower than the C++ (that is, elapsed time of the 10,000 outer loop for
>>>>> both).
>>>> I just use strtoll. Why reinvent the wheel?
>>>
>>> It needs to be stroull() for this purpose, which is more elusive (gcc
>>> has it on Windows, but the two other compilers I have don't),
>>
>> gcc does not provide strtoll() or strtoull(). Both are provided by the
>> library, not by the compiler. (And both were introduced in C99, so I'd
>> be at least mildly surprised by an implementation that provides one
>> but not the other.)
>>
>> I know you're tired of people pointing out that the compiler (gcc
>> in this case) does not provide library functions. The solution is
>> for you to stop making that mistake. Or should I assume you enjoy
>> these arguments?
>
>gcc/tdm compiles programs using strtoull.
>
>bcc/tcc fail with a link error, unless I include this line:

Then they are POS compilers, or you're using them incorrectly,
such as forgetting to include <stdlib.h>.

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<tYzHJ.11748$1_.11324@fx37.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!npeer.as286.net!npeer-ng0.as286.net!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx37.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: on an analogy for verifying whether another digit fits (into an unsigned type)
Newsgroups: comp.lang.c
References: <86mtjws9cg.fsf@levado.to> <ss8g0e$8dv$1@dont-email.me> <6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com> <ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me> <ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad> <ss9u3b$jdr$1@dont-email.me> <87pmoixf59.fsf@nosuchdomain.example.com> <sskqvb$im7$1@dont-email.me> <87wniq0w8m.fsf@bsb.me.uk> <ssm23g$q5s$1@dont-email.me>
Lines: 8
Message-ID: <tYzHJ.11748$1_.11324@fx37.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Mon, 24 Jan 2022 15:54:01 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 24 Jan 2022 15:54:01 GMT
X-Received-Bytes: 1317
 by: Scott Lurndal - Mon, 24 Jan 2022 15:54 UTC

Bart <bc@freeuk.com> writes:

> c:\c>tcc c.c
> tcc: error: undefined symbol 'strtoull'

strtoull is a POSIX symbol. If the tcc implementation you
are using supports POSIX, then you've likely misconfigured tcc,
otherwise you're tilting at windmills.

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

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

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an unsigned type)
Date: Mon, 24 Jan 2022 15:57:21 +0000
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <87r18x15zy.fsf@bsb.me.uk>
References: <86mtjws9cg.fsf@levado.to> <ss8g0e$8dv$1@dont-email.me>
<6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com>
<ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me>
<ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad>
<ss9u3b$jdr$1@dont-email.me> <87pmoixf59.fsf@nosuchdomain.example.com>
<sskqvb$im7$1@dont-email.me> <87wniq0w8m.fsf@bsb.me.uk>
<ssm23g$q5s$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="af9c25630be9b14368cf3170ae6cca15";
logging-data="31156"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/I09rGXvqJBpu2+mW6tDN5z/f98i7fQps="
Cancel-Lock: sha1:PU1EzxD6ID5+/fEGZ6V0O2pJMX0=
sha1:Zpd9YtKwFrKNluurE9oyLeETQmg=
X-BSB-Auth: 1.f1623a7106d2b3bb3c2c.20220124155721GMT.87r18x15zy.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 24 Jan 2022 15:57 UTC

Bart <bc@freeuk.com> writes:

> On 24/01/2022 01:15, Ben Bacarisse wrote:
>> Bart <bc@freeuk.com> writes:

>>> #define strtoull _strtoui64
>> Which, of course, means "unless I don't use strtoull".
>
> It's better not to. If I were to post code anywhere that used it, then
> at least some people trying it wouldn't be able to build it. And I'm
> not having /my/ code full of those implementation-specific conditional
> blocks that I despise.

What level of broken are you prepared to work around? If I produce a C
implementation, based, say, on tcc, which fails to link strlen, would
you feel you have to work round that? I don't think so. You'd tell me
that my implementation is broken.

Conditional blocks are ugly, but writing potentially buggy code just to
avoid a standard library function is also hardly ideal.

> For the same reason, I tend not to write shared code that uses '$' in
> identifiers, because tcc doesn't support it.

Not even in the same ball-park. No C implementation is required to
support $ in identifiers, but every conforming C implementation is
required to support strtoull.

>> If your code must work with non-standard C implementations, then there
>> might well be a whole raft of things you should avoid. But since you
>> seem to use C a lot, wouldn't it be better either to try to fix your tcc
>> installation or to simply uninstall it?
>
> What do you mean by fix? Fixing my tcc doesn't help people compiling
> my code unless everybody fixes theirs too.

I didn't realise anyone else compiled your code. I thought your C
projects were personal ones. You could just say that a conforming C
compiler is required. Would that really disenfranchise a large
user-base?

--
Ben.

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<ssmlgt$9hn$1@dont-email.me>

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an
unsigned type)
Date: Mon, 24 Jan 2022 16:52:46 +0000
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <ssmlgt$9hn$1@dont-email.me>
References: <86mtjws9cg.fsf@levado.to> <ss8g0e$8dv$1@dont-email.me>
<6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com>
<ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me>
<ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad>
<ss9u3b$jdr$1@dont-email.me> <87pmoixf59.fsf@nosuchdomain.example.com>
<sskqvb$im7$1@dont-email.me> <87wniq0w8m.fsf@bsb.me.uk>
<ssm23g$q5s$1@dont-email.me> <87r18x15zy.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jan 2022 16:52:45 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ffd3f67a34ea05229c22240f8aaaf2f6";
logging-data="9783"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/57i59VtxQyQETJwN9r3uq0DDyxMHTzK0="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:KE7hYROkeBKwjKvmAY0A84Ta9n0=
In-Reply-To: <87r18x15zy.fsf@bsb.me.uk>
 by: Bart - Mon, 24 Jan 2022 16:52 UTC

On 24/01/2022 15:57, Ben Bacarisse wrote:
> Bart <bc@freeuk.com> writes:
>
>> On 24/01/2022 01:15, Ben Bacarisse wrote:
>>> Bart <bc@freeuk.com> writes:
>
>>>> #define strtoull _strtoui64
>>> Which, of course, means "unless I don't use strtoull".
>>
>> It's better not to. If I were to post code anywhere that used it, then
>> at least some people trying it wouldn't be able to build it. And I'm
>> not having /my/ code full of those implementation-specific conditional
>> blocks that I despise.
>
> What level of broken are you prepared to work around? If I produce a C
> implementation, based, say, on tcc, which fails to link strlen, would
> you feel you have to work round that? I don't think so. You'd tell me
> that my implementation is broken.

/That's/ not in the same ballpark! Without strlen, very few C programs
would build. Any problems would quickly be found.

With strtoull, people can spend decades coding C and not need to use it
or encounter it. Apparently no one has with tcc on Windows, or they
couldn't find where to file a bug report.

> Conditional blocks are ugly, but writing potentially buggy code just to
> avoid a standard library function is also hardly ideal.
>
>> For the same reason, I tend not to write shared code that uses '$' in
>> identifiers, because tcc doesn't support it.
>
> Not even in the same ball-park. No C implementation is required to
> support $ in identifiers, but every conforming C implementation is
> required to support strtoull.

Yet most do support '$'; why bother to allow it, unless they expect
people to use it?

The exceptions I've come across are tcc, and lccwin which has limited
support (I think only as a starter).

I used '$' extensively in generated C (when it occurs in the source
language, and is used as the 'dot' in qualified names). But because tcc
is such an important target for me, I had to work around it.

>
>>> If your code must work with non-standard C implementations, then there
>>> might well be a whole raft of things you should avoid. But since you
>>> seem to use C a lot, wouldn't it be better either to try to fix your tcc
>>> installation or to simply uninstall it?
>>
>> What do you mean by fix? Fixing my tcc doesn't help people compiling
>> my code unless everybody fixes theirs too.
>
> I didn't realise anyone else compiled your code.

A lot of my C code is posted on forums or linked to. If it's not to be
compiled as C, then there's no point in using C, as my own language is
much sweeter.

So if I go to that trouble, it has to compile. But I only test with tcc,
gcc and bcc. Usually if it passes bcc, it will work with anything, other
than tcc + $ symbols.

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<ad525f87-3521-4478-addd-bdef85ae019bn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:19e9:: with SMTP id q9mr5861383qvc.70.1643048234063; Mon, 24 Jan 2022 10:17:14 -0800 (PST)
X-Received: by 2002:ad4:5e88:: with SMTP id jl8mr15431407qvb.10.1643048233956; Mon, 24 Jan 2022 10:17:13 -0800 (PST)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!tr1.eu1.usenetexpress.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!border1.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: Mon, 24 Jan 2022 10:17:13 -0800 (PST)
In-Reply-To: <ssmlgt$9hn$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=94.246.251.164; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 94.246.251.164
References: <86mtjws9cg.fsf@levado.to> <ss8g0e$8dv$1@dont-email.me> <6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com> <ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me> <ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad> <ss9u3b$jdr$1@dont-email.me> <87pmoixf59.fsf@nosuchdomain.example.com> <sskqvb$im7$1@dont-email.me> <87wniq0w8m.fsf@bsb.me.uk> <ssm23g$q5s$1@dont-email.me> <87r18x15zy.fsf@bsb.me.uk> <ssmlgt$9hn$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ad525f87-3521-4478-addd-bdef85ae019bn@googlegroups.com>
Subject: Re: on an analogy for verifying whether another digit fits (into an unsigned type)
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Mon, 24 Jan 2022 18:17:14 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 21
 by: Öö Tiib - Mon, 24 Jan 2022 18:17 UTC

On Monday, 24 January 2022 at 18:52:57 UTC+2, Bart wrote:
> On 24/01/2022 15:57, Ben Bacarisse wrote:
> > Bart <b...@freeuk.com> writes:
> >
> >> For the same reason, I tend not to write shared code that uses '$' in
> >> identifiers, because tcc doesn't support it.
> >
> > Not even in the same ball-park. No C implementation is required to
> > support $ in identifiers, but every conforming C implementation is
> > required to support strtoull.
>
> Yet most do support '$'; why bother to allow it, unless they expect
> people to use it?

They expect that people may need to use it. ABI on several platforms
allows '$' in symbol names and there might arise need to link
C code to library or shared object that contains such name. The
implementer tries to be helpful by allowing what ABI allows and
what can not otherwise contradict with C syntax. It does not mean
that one should start to use '$' instead of 'S' to look cool or
something.

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

<09CHJ.15015$vN.6534@fx15.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx15.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: on an analogy for verifying whether another digit fits (into an unsigned type)
Newsgroups: comp.lang.c
References: <86mtjws9cg.fsf@levado.to> <6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com> <ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me> <ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad> <ss9u3b$jdr$1@dont-email.me> <87pmoixf59.fsf@nosuchdomain.example.com> <sskqvb$im7$1@dont-email.me> <87wniq0w8m.fsf@bsb.me.uk> <ssm23g$q5s$1@dont-email.me> <87r18x15zy.fsf@bsb.me.uk> <ssmlgt$9hn$1@dont-email.me> <ad525f87-3521-4478-addd-bdef85ae019bn@googlegroups.com>
Lines: 25
Message-ID: <09CHJ.15015$vN.6534@fx15.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Mon, 24 Jan 2022 18:23:56 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 24 Jan 2022 18:23:56 GMT
X-Received-Bytes: 2334
 by: Scott Lurndal - Mon, 24 Jan 2022 18:23 UTC

=?UTF-8?B?w5bDtiBUaWli?= <ootiib@hot.ee> writes:
>On Monday, 24 January 2022 at 18:52:57 UTC+2, Bart wrote:
>> On 24/01/2022 15:57, Ben Bacarisse wrote:
>> > Bart <b...@freeuk.com> writes:
>> >
>> >> For the same reason, I tend not to write shared code that uses '$' in
>> >> identifiers, because tcc doesn't support it.
>> >
>> > Not even in the same ball-park. No C implementation is required to
>> > support $ in identifiers, but every conforming C implementation is
>> > required to support strtoull.
>>
>> Yet most do support '$'; why bother to allow it, unless they expect
>> people to use it?
>
>They expect that people may need to use it. ABI on several platforms
>allows '$' in symbol names and there might arise need to link
>C code to library or shared object that contains such name. The
>implementer tries to be helpful by allowing what ABI allows and
>what can not otherwise contradict with C syntax. It does not mean
>that one should start to use '$' instead of 'S' to look cool or
>something.

C on VMS, for example, required '$' in identifiers for the system
services (library functions, system calls) such as $QIOW or $GETJPI et alia.

Re: on an analogy for verifying whether another digit fits (into an unsigned type)

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

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an unsigned type)
Date: Mon, 24 Jan 2022 13:08:33 -0800
Organization: None to speak of
Lines: 24
Message-ID: <87czkgon8u.fsf@nosuchdomain.example.com>
References: <86mtjws9cg.fsf@levado.to> <ss8g0e$8dv$1@dont-email.me>
<6df246f4-204e-4fd1-ad91-bb4fce96f100n@googlegroups.com>
<ss9arn$rtm$1@dont-email.me> <ss9g7q$5ud$1@dont-email.me>
<ss9l6b$ctv$1@dont-email.me> <C0ZFJ.134459$Gco3.62864@fx01.iad>
<ss9u3b$jdr$1@dont-email.me> <87pmoixf59.fsf@nosuchdomain.example.com>
<sskqvb$im7$1@dont-email.me> <87wniq0w8m.fsf@bsb.me.uk>
<ssm23g$q5s$1@dont-email.me> <tYzHJ.11748$1_.11324@fx37.iad>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="94b3a3008f708f7b40cdf3a125e51cf3";
logging-data="19835"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19oisGW3ZPafzv38UtRm4tw"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:UyoYMEIUx1I0CCrtwo5M5Hn6dOs=
sha1:ontFVIJsKiA4uAQEbd654JWjMYA=
 by: Keith Thompson - Mon, 24 Jan 2022 21:08 UTC

scott@slp53.sl.home (Scott Lurndal) writes:
> Bart <bc@freeuk.com> writes:
>
>> c:\c>tcc c.c
>> tcc: error: undefined symbol 'strtoull'
>
> strtoull is a POSIX symbol. If the tcc implementation you
> are using supports POSIX, then you've likely misconfigured tcc,
> otherwise you're tilting at windmills.

I'm not sure what you mean by POSIX symbol. In C99 and later, strtoll
and strtoull are both defined by ISO C, and will be supported by any
conforming (hosted) implementation. Neither was defined by C90. I
suppose earlier editions of POSIX may have defined strtoll and strtoull
for pre-C99 compilers, but they depend on the long long and unsigned
long long types.

Did pre-C99 versions of POSIX (optionally?) specify long long and
unsigned long long before ISO C did?

--
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 */

Pages:123
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor