Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

6 May, 2024: The networking issue during the past two days has been identified and appears to be fixed. Will keep monitoring.


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)

<878rv4omy0.fsf@nosuchdomain.example.com>

  copy mid

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

  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:15:03 -0800
Organization: None to speak of
Lines: 30
Message-ID: <878rv4omy0.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>
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="U2FsdGVkX19guxqL/6yEec67SqnM0d1v"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:laMqL13VmM6tfSzpyBS5kOvRTGg=
sha1:Lu24Yu3mpZ+02Pxv0bAFk4yf+qM=
 by: Keith Thompson - Mon, 24 Jan 2022 21:15 UTC

Bart <bc@freeuk.com> writes:
> On 24/01/2022 01:15, Ben Bacarisse wrote:
[...]
>> 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.

Again, both strtoll and strtoull have been standard since ISO C 1999.
I remember when it wasn't safe to assume C99 support for portable
code, but I don't get the impression that that's the case anymore.
Workarounds might still be needed, but I suggest it's not worth
worrying about too much.

(Bart knows that it's the library, not the tcc compiler, that supports
or doesn't support strtoull. I will not argue with him about that. And
as I recall we recently had a discussion indicating that there are
multiple versions of msvcrt.dll.)

[...]

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

<ssn7mo$e3q$1@dont-email.me>

  copy mid

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

  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 22:03:04 +0000
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <ssn7mo$e3q$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> <sWzHJ.11681$1_.11496@fx37.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jan 2022 22:03:04 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ffd3f67a34ea05229c22240f8aaaf2f6";
logging-data="14458"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/yjT0U0m24RHHlQnPai/w2uJKnZIMIMYQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:+6l/WUTvYaomcnoElmEM+QE5W34=
In-Reply-To: <sWzHJ.11681$1_.11496@fx37.iad>
 by: Bart - Mon, 24 Jan 2022 22:03 UTC

On 24/01/2022 15:51, Scott Lurndal 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, unless I include this line:
>
> Then they are POS compilers, or you're using them incorrectly,
> such as forgetting to include <stdlib.h>.

I said it's a link error. They both depend on the msvcrt.dll library for
standard C functions, and strtoull is not defined in that library. (It
is defined inside ucrtbase.dll, but then that's missing stuff like printf.)

As certain people are so fond of reminding me, the library is a
completely different entity from the compiler, so it is apparently not a
compiler problem as both provide a proper API entry for that function.

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

<T3GHJ.875$dV.689@fx44.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx44.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> <tYzHJ.11748$1_.11324@fx37.iad> <87czkgon8u.fsf@nosuchdomain.example.com>
Lines: 23
Message-ID: <T3GHJ.875$dV.689@fx44.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Mon, 24 Jan 2022 22:51:31 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 24 Jan 2022 22:51:31 GMT
X-Received-Bytes: 2167
 by: Scott Lurndal - Mon, 24 Jan 2022 22:51 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>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.

POSIX generally incorporates a C standard by reference, and we
had implemented (circa 1989) the strto[u]ll functions in our versions
of Unix for the Motorla 88100. My early specs are in storage,
so I can't refer back to them to see when 1003.4 or X/Open adopted
them.

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

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

  copy mid

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

  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 15:33:18 -0800
Organization: None to speak of
Lines: 58
Message-ID: <87v8y8n1z5.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> <sWzHJ.11681$1_.11496@fx37.iad>
<ssn7mo$e3q$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="fbd031f938b902ca86c8b061f35a7f8c";
logging-data="4408"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX190DTphX6r89/0sJrcm4uTx"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:i4W6lQ6AB7Dj3mZh3WiZCd8+Wj8=
sha1:NGEPcbtHFyij1AW+Inyitc3trcU=
 by: Keith Thompson - Mon, 24 Jan 2022 23:33 UTC

Bart <bc@freeuk.com> writes:
> On 24/01/2022 15:51, Scott Lurndal wrote:
>> Bart <bc@freeuk.com> writes:
[...]
>>> 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>.
>
> I said it's a link error. They both depend on the msvcrt.dll library
> for standard C functions, and strtoull is not defined in that
> library. (It is defined inside ucrtbase.dll, but then that's missing
> stuff like printf.)

An aside: I have three different versions of msvcrt.dll on my Windows
system. None of them appear to support strtoll or strtoull.

> As certain people are so fond of reminding me, the library is a
> completely different entity from the compiler, so it is apparently not
> a compiler problem as both provide a proper API entry for that
> function.

I think that may be the first time you've actually acknowledged that.

However, it's not necessary for the compiler itself to have a
"proper API entry" for a library function, or to know anything
about it. Using strtol as an example (since it's supported all the
way back to C89/C90), the compiler knows how to call it because it
sees the declaration in <stdlib.h>. (For a C90 compiler, if you
don't include the header, the compiler will assume an incorrect
declaration for strtol when it sees a call.) <stdlib.h>, which provides
the declaration, and whatever file(?) provides the code that actually
implements the function, are typically provided by the same package (or
at least they must be kept closely in synch).

A call to a standard library function is just a function call,
unless the implementation chooses to do something fancy.

Some compilers incorporate some information about some standard
library functions for the purpose of producing better diagnostics
and/or optimizations. But if, for example, a future standard
added an strtofoo() function, no *compiler* changes would be needed
to support it, as long as the headers and library implementation
supported it correctly. The same thing happens if you add your own
footobar() function and provide a header that declares it (using
a different name because names starting with "str" are reserved).

Of course if you're using an implementation that doesn't conform to
C99, you're not guaranteed to be able to use strtoll() or strtoull(),
and you'll have to find some workaround. An implementation that
depends entirely on msvcrt.dll for the C standard library cannot
conform to C99 (unless there's a later version of msvcrt.dll that I'm
not aware of). I doubt that very many people have to deal with that.
(I presume you'll agree that you are not a typical user.)

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

<ssnf4l$gb1$1@dont-email.me>

  copy mid

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

  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: Tue, 25 Jan 2022 00:09:58 +0000
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <ssnf4l$gb1$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> <sWzHJ.11681$1_.11496@fx37.iad>
<ssn7mo$e3q$1@dont-email.me> <87v8y8n1z5.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 25 Jan 2022 00:09:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="1abaccf232ce75819d12e3d24e0535e8";
logging-data="16737"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+CR6z3GdH4Hqv7wN8XBFy17fcSFk0cd4U="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:YZt6jzTp/KeVIS6nmnM6KNoglOk=
In-Reply-To: <87v8y8n1z5.fsf@nosuchdomain.example.com>
 by: Bart - Tue, 25 Jan 2022 00:09 UTC

On 24/01/2022 23:33, Keith Thompson wrote:
> Bart <bc@freeuk.com> writes:
>> On 24/01/2022 15:51, Scott Lurndal wrote:
>>> Bart <bc@freeuk.com> writes:
> [...]
>>>> 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>.
>>
>> I said it's a link error. They both depend on the msvcrt.dll library
>> for standard C functions, and strtoull is not defined in that
>> library. (It is defined inside ucrtbase.dll, but then that's missing
>> stuff like printf.)
>
> An aside: I have three different versions of msvcrt.dll on my Windows
> system. None of them appear to support strtoll or strtoull.
>
>> As certain people are so fond of reminding me, the library is a
>> completely different entity from the compiler, so it is apparently not
>> a compiler problem as both provide a proper API entry for that
>> function.
>
> I think that may be the first time you've actually acknowledged that.
>
> However, it's not necessary for the compiler itself to have a
> "proper API entry" for a library function, or to know anything
> about it. Using strtol as an example (since it's supported all the
> way back to C89/C90), the compiler knows how to call it because it
> sees the declaration in <stdlib.h>.

The declaration is what I mean by 'API' entry. I'm using 'API' to mean
all the information needed by the programmer to write calls to a
function, and for the compiler to check those calls and generate the
proper code, usually inside some header file.

> (I presume you'll agree that you are not a typical user.)

I guess not. I make considerably more use of the C standard library from
outside C than inside it. However msvcrt.dll exports just over 1300
functions, but I only ever use a few dozen. strtoull is one of the 1250
or so that I haven't yet needed.

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

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

  copy mid

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

  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 21:14:44 -0800
Organization: None to speak of
Lines: 52
Message-ID: <87mtjkmm63.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> <sWzHJ.11681$1_.11496@fx37.iad>
<ssn7mo$e3q$1@dont-email.me> <87v8y8n1z5.fsf@nosuchdomain.example.com>
<ssnf4l$gb1$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="fbd031f938b902ca86c8b061f35a7f8c";
logging-data="5351"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/6aO33QPFjbirnrSARzQn1"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:mgARXw776Uch5Th1+dcLGFBeTMg=
sha1:TFGzanFP6L4YcdtAbbR3xXJgOcI=
 by: Keith Thompson - Tue, 25 Jan 2022 05:14 UTC

Bart <bc@freeuk.com> writes:
> On 24/01/2022 23:33, Keith Thompson wrote:
>> Bart <bc@freeuk.com> writes:
>>> On 24/01/2022 15:51, Scott Lurndal wrote:
>>>> Bart <bc@freeuk.com> writes:
>> [...]
>>>>> 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>.
>>>
>>> I said it's a link error. They both depend on the msvcrt.dll library
>>> for standard C functions, and strtoull is not defined in that
>>> library. (It is defined inside ucrtbase.dll, but then that's missing
>>> stuff like printf.)
>> An aside: I have three different versions of msvcrt.dll on my
>> Windows
>> system. None of them appear to support strtoll or strtoull.
>>
>>> As certain people are so fond of reminding me, the library is a
>>> completely different entity from the compiler, so it is apparently not
>>> a compiler problem as both provide a proper API entry for that
>>> function.
>> I think that may be the first time you've actually acknowledged
>> that.
>> However, it's not necessary for the compiler itself to have a
>> "proper API entry" for a library function, or to know anything
>> about it. Using strtol as an example (since it's supported all the
>> way back to C89/C90), the compiler knows how to call it because it
>> sees the declaration in <stdlib.h>.
>
> The declaration is what I mean by 'API' entry. I'm using 'API' to mean
> all the information needed by the programmer to write calls to a
> function, and for the compiler to check those calls and generate the
> proper code, usually inside some header file.

You said that "both provide a proper API entry for that function", where
the context indicated that "both" referred to the compiler and the
runtime library. The compiler needs to *see* a C function declaration
(a clearer description IMHO than "proper API entry"), presumably in a
header file, but that declaration is not provided by the compiler
itself. (Some headers might be distributed as part of the same package
as the compiler rather than as part of the runtime library; for example
gcc provides <stddef.h>.)

I think we both understand all this. Please don't obfuscate it further.

[...]

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

<sss99t$16ui$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!Puiiztk9lHEEQC0y3uUjRA.user.46.165.242.75.POSTED!not-for-mail
From: inva...@invalid.add (Manfred)
Newsgroups: comp.lang.c
Subject: Re: on an analogy for verifying whether another digit fits (into an
unsigned type)
Date: Wed, 26 Jan 2022 21:01:00 +0100
Organization: Aioe.org NNTP Server
Message-ID: <sss99t$16ui$1@gioia.aioe.org>
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> <sWzHJ.11681$1_.11496@fx37.iad>
<ssn7mo$e3q$1@dont-email.me> <87v8y8n1z5.fsf@nosuchdomain.example.com>
<ssnf4l$gb1$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="39890"; posting-host="Puiiztk9lHEEQC0y3uUjRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:52.0) Gecko/20100101
Thunderbird/52.9.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Manfred - Wed, 26 Jan 2022 20:01 UTC

On 1/25/2022 1:09 AM, Bart wrote:
> On 24/01/2022 23:33, Keith Thompson wrote:
>> Bart <bc@freeuk.com> writes:
>>> On 24/01/2022 15:51, Scott Lurndal wrote:
>>>> Bart <bc@freeuk.com> writes:
>> [...]
>>>>> 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>.
>>>
>>> I said it's a link error. They both depend on the msvcrt.dll library
>>> for standard C functions, and strtoull is not defined in that
>>> library. (It is defined inside ucrtbase.dll, but then that's missing
>>> stuff like printf.)
>>
>> An aside: I have three different versions of msvcrt.dll on my Windows
>> system.  None of them appear to support strtoll or strtoull.
>>
>>> As certain people are so fond of reminding me, the library is a
>>> completely different entity from the compiler, so it is apparently not
>>> a compiler problem as both provide a proper API entry for that
>>> function.
>>
>> I think that may be the first time you've actually acknowledged that.
>>
>> However, it's not necessary for the compiler itself to have a
>> "proper API entry" for a library function, or to know anything
>> about it.  Using strtol as an example (since it's supported all the
>> way back to C89/C90), the compiler knows how to call it because it
>> sees the declaration in <stdlib.h>.
>
> The declaration is what I mean by 'API' entry. I'm using 'API' to mean
> all the information needed by the programmer to write calls to a
> function, and for the compiler to check those calls and generate the
> proper code, usually inside some header file.
>
>
>> (I presume you'll agree that you are not a typical user.)
>
> I guess not. I make considerably more use of the C standard library from
> outside C than inside it. However msvcrt.dll exports just over 1300
> functions, but I only ever use a few dozen. strtoull is one of the 1250
> or so that I haven't yet needed.
>
>

Most importantly, msvcrt.dll is *not* a C standard library. It is a
Microsoft library that exports C runtime functions for their own
products [*].
It is not documented anywhere as a C *standard* library.
To be explicit, this means that you can't complain if it does not export
a conforming implementation of C, and if you find inconsistencies with
the standard it is certainly not the fault neither of the language nor
of the standard.

It is your choice if you want to use it, but it should be no surprise at
all if some C standard function is not available, or shows a different
behaviour, or even has a different signature from the ISO standard. It
is *not* a C standard library. (I guess I already wrote that)

In case the above were not sufficiently clear, not even Microsoft does
list 'msvcrt.dll' among the redistributables for software developed with
their development environment for C, which is Visual Studio, and is the
only product for which they document /some/ conformancy with ISO C.

cfr. some information from Microsoft:
https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-170

As for some background, in the '90s 'msvcrt.dll' used to be Microsoft's
"C runtime library" and it was part of the redistributables for early
versions of their development product for C, which was called Visual
C++. In this respect, you might say that /at that time/ it was part of
Microsoft's implementation of C.
That said, the necessary remark is that, expecially at that time,
Microsoft's implementation of C was well known for being wildly
diverging from ISO C.

([*] More specifically, the page I linked above lists 'msvcrt.lib' among
the "libraries that implement CRT initialization and termination" for C
programs written with Visual Studio.)

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

<ssscd6$l3f$1@dont-email.me>

  copy mid

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

  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: Wed, 26 Jan 2022 20:53:58 +0000
Organization: A noiseless patient Spider
Lines: 74
Message-ID: <ssscd6$l3f$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> <sWzHJ.11681$1_.11496@fx37.iad>
<ssn7mo$e3q$1@dont-email.me> <87v8y8n1z5.fsf@nosuchdomain.example.com>
<ssnf4l$gb1$1@dont-email.me> <sss99t$16ui$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 26 Jan 2022 20:53:58 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="c908c348916be4908411475ff723c0c8";
logging-data="21615"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+aSL8qgk5Uu1k6B3WMNZx47HFlR4TNDFw="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:IjTQSwUSVSZY+dWE91VJJHRzH2c=
In-Reply-To: <sss99t$16ui$1@gioia.aioe.org>
 by: Bart - Wed, 26 Jan 2022 20:53 UTC

On 26/01/2022 20:01, Manfred wrote:
> On 1/25/2022 1:09 AM, Bart wrote:
>> On 24/01/2022 23:33, Keith Thompson wrote:
>>> Bart <bc@freeuk.com> writes:
>>>> On 24/01/2022 15:51, Scott Lurndal wrote:
>>>>> Bart <bc@freeuk.com> writes:
>>> [...]
>>>>>> 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>.
>>>>
>>>> I said it's a link error. They both depend on the msvcrt.dll library
>>>> for standard C functions, and strtoull is not defined in that
>>>> library. (It is defined inside ucrtbase.dll, but then that's missing
>>>> stuff like printf.)
>>>
>>> An aside: I have three different versions of msvcrt.dll on my Windows
>>> system.  None of them appear to support strtoll or strtoull.
>>>
>>>> As certain people are so fond of reminding me, the library is a
>>>> completely different entity from the compiler, so it is apparently not
>>>> a compiler problem as both provide a proper API entry for that
>>>> function.
>>>
>>> I think that may be the first time you've actually acknowledged that.
>>>
>>> However, it's not necessary for the compiler itself to have a
>>> "proper API entry" for a library function, or to know anything
>>> about it.  Using strtol as an example (since it's supported all the
>>> way back to C89/C90), the compiler knows how to call it because it
>>> sees the declaration in <stdlib.h>.
>>
>> The declaration is what I mean by 'API' entry. I'm using 'API' to mean
>> all the information needed by the programmer to write calls to a
>> function, and for the compiler to check those calls and generate the
>> proper code, usually inside some header file.
>>
>>
>>> (I presume you'll agree that you are not a typical user.)
>>
>> I guess not. I make considerably more use of the C standard library
>> from outside C than inside it. However msvcrt.dll exports just over
>> 1300 functions, but I only ever use a few dozen. strtoull is one of
>> the 1250 or so that I haven't yet needed.
>>
>>
>
> Most importantly, msvcrt.dll is *not* a C standard library. It is a
> Microsoft library that exports C runtime functions for their own
> products [*].
> It is not documented anywhere as a C *standard* library.
> To be explicit, this means that you can't complain if it does not export
> a conforming implementation of C, and if you find inconsistencies with
> the standard it is certainly not the fault neither of the language nor
> of the standard.
>
> It is your choice if you want to use it,

I think I first came across this library when I started to work with
Windows sometime in the 90s.

I didn't really associate with it C (I didn't use it from that
language); it seemed just another set of WinAPI functions from the docs,
all of which used C-style declarations.

It seems to be still present on every Windows OS, so I don't think it's
going anywhere.

msvcrt.dll is also used by gcc/tdm on Windows as well as tcc, for
building programs. If it suddenly disappeared, then quite a lot of
programs would stop working...

.... including gcc.exe and tcc.exe which themselves both import msvcrt.dll.

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

<sst0qm$11t$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!V1SGbX7OqUFeXvR6beMc1g.user.46.165.242.75.POSTED!not-for-mail
From: non...@add.invalid (Manfred)
Newsgroups: comp.lang.c
Subject: Re: on an analogy for verifying whether another digit fits (into an
unsigned type)
Date: Thu, 27 Jan 2022 03:42:29 +0100
Organization: Aioe.org NNTP Server
Message-ID: <sst0qm$11t$1@gioia.aioe.org>
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> <sWzHJ.11681$1_.11496@fx37.iad>
<ssn7mo$e3q$1@dont-email.me> <87v8y8n1z5.fsf@nosuchdomain.example.com>
<ssnf4l$gb1$1@dont-email.me> <sss99t$16ui$1@gioia.aioe.org>
<ssscd6$l3f$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="1085"; posting-host="V1SGbX7OqUFeXvR6beMc1g.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Manfred - Thu, 27 Jan 2022 02:42 UTC

On 1/26/2022 9:53 PM, Bart wrote:
> On 26/01/2022 20:01, Manfred wrote:
>> On 1/25/2022 1:09 AM, Bart wrote:
>>> On 24/01/2022 23:33, Keith Thompson wrote:
>>>> Bart <bc@freeuk.com> writes:
>>>>> On 24/01/2022 15:51, Scott Lurndal wrote:
>>>>>> Bart <bc@freeuk.com> writes:
>>>> [...]
>>>>>>> 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>.
>>>>>
>>>>> I said it's a link error. They both depend on the msvcrt.dll library
>>>>> for standard C functions, and strtoull is not defined in that
>>>>> library. (It is defined inside ucrtbase.dll, but then that's missing
>>>>> stuff like printf.)
>>>>
>>>> An aside: I have three different versions of msvcrt.dll on my Windows
>>>> system.  None of them appear to support strtoll or strtoull.
>>>>
>>>>> As certain people are so fond of reminding me, the library is a
>>>>> completely different entity from the compiler, so it is apparently not
>>>>> a compiler problem as both provide a proper API entry for that
>>>>> function.
>>>>
>>>> I think that may be the first time you've actually acknowledged that.
>>>>
>>>> However, it's not necessary for the compiler itself to have a
>>>> "proper API entry" for a library function, or to know anything
>>>> about it.  Using strtol as an example (since it's supported all the
>>>> way back to C89/C90), the compiler knows how to call it because it
>>>> sees the declaration in <stdlib.h>.
>>>
>>> The declaration is what I mean by 'API' entry. I'm using 'API' to
>>> mean all the information needed by the programmer to write calls to a
>>> function, and for the compiler to check those calls and generate the
>>> proper code, usually inside some header file.
>>>
>>>
>>>> (I presume you'll agree that you are not a typical user.)
>>>
>>> I guess not. I make considerably more use of the C standard library
>>> from outside C than inside it. However msvcrt.dll exports just over
>>> 1300 functions, but I only ever use a few dozen. strtoull is one of
>>> the 1250 or so that I haven't yet needed.
>>>
>>>
>>
>> Most importantly, msvcrt.dll is *not* a C standard library. It is a
>> Microsoft library that exports C runtime functions for their own
>> products [*].
>> It is not documented anywhere as a C *standard* library.
>> To be explicit, this means that you can't complain if it does not
>> export a conforming implementation of C, and if you find
>> inconsistencies with the standard it is certainly not the fault
>> neither of the language nor of the standard.
>>
>> It is your choice if you want to use it,
>
> I think I first came across this library when I started to work with
> Windows sometime in the 90s.
>
> I didn't really associate with it C (I didn't use it from that
> language); it seemed just another set of WinAPI functions from the docs,
> all of which used C-style declarations.
>
> It seems to be still present on every Windows OS, so I don't think it's
> going anywhere.
>
> msvcrt.dll is also used by gcc/tdm on Windows as well as tcc, for
> building programs. If it suddenly disappeared, then quite a lot of
> programs would stop working...
>
> ... including gcc.exe and tcc.exe which themselves both import msvcrt.dll.
>

Yes, msvcrt.dll has been part of Windows for a very long time, and most
probably it will stay this way, although one has to notice that with
Microsoft this kind of prediction has gotten harder and harder as of
recent - I believe they have thrown out more stuff out of the window in
the last five years than in the previous 35, to the point that today it
is even impossible to get redistributables that were first released in 2010.

But that was not my point.

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

<86wnij8hq6.fsf@levado.to>

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an unsigned type)
Date: Fri, 28 Jan 2022 22:15:45 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86wnij8hq6.fsf@levado.to>
References: <86mtjws9cg.fsf@levado.to> <ss1p1k$shu$1@dont-email.me>
<86k0eyplyy.fsf@levado.to> <87a6fu5l2q.fsf@bsb.me.uk>
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";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:ZjXFODFzhHMTdqslfRY2v1W42yI=
 by: Meredith Montgomery - Sat, 29 Jan 2022 01:15 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> Meredith Montgomery <mmontgomery@levado.to> writes:
>
>> Bart <bc@freeuk.com> writes:
>>
>>> On 16/01/2022 02:27, Meredith Montgomery wrote:
>>>> 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)
>>>
>>> Dividing by 10 each time is unnecessary (even if usually optimised to
>>> shifts and multiplies).
>>>
>>> You only need to make this check after you've already processed 19
>>> characters, as it could overflow on the 20th, but not before.
>>>
>>> I think when pos >= 18.
>>
>> I suppose you're right, but imagine putting such check there. It would
>> take even more paragraphs to explain it to myself some time later when
>> I'm trying to figure out what I wrote a while back.
>
> You could just check that the array contains a string of digits
> lexicographically less than or equal to 18446744073709551615. If there
> are fewer digits than this, or, at every position, the digit you have is
> no greater than the corresponding digit of that number, you are ok.

That seems correct, but if I change the size of my register, then I must
replace the number too. :-)

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

<86k0ej8hai.fsf@levado.to>

  copy mid

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

  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: on an analogy for verifying whether another digit fits (into an unsigned type)
Date: Fri, 28 Jan 2022 22:25:09 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86k0ej8hai.fsf@levado.to>
References: <86mtjws9cg.fsf@levado.to> <86fsphrcsu.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="63060"; posting-host="SZor4ZqbvgPVVsWQ21e4cw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:cV1Q6l7xZijO5mCxeSgJuMfzCMo=
 by: Meredith Montgomery - Sat, 29 Jan 2022 01:25 UTC

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

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

That's a brilliant explanation!

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

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

  copy mid

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

  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: Sat, 29 Jan 2022 02:36:38 +0000
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <87k0ejxo7d.fsf@bsb.me.uk>
References: <86mtjws9cg.fsf@levado.to> <ss1p1k$shu$1@dont-email.me>
<86k0eyplyy.fsf@levado.to> <87a6fu5l2q.fsf@bsb.me.uk>
<86wnij8hq6.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="00be0330ed62b735868e93f7a4aba188";
logging-data="26812"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+93ipoRBANeI/RXZBMZpIXhqiCGvvDprA="
Cancel-Lock: sha1:wM9+yKejw/Gfx3xSurbd0W8XKhA=
sha1:an4yEB3NmT8YMDhe5RZKbQii+Bc=
X-BSB-Auth: 1.7b514e1dc20125932537.20220129023638GMT.87k0ejxo7d.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 29 Jan 2022 02:36 UTC

Meredith Montgomery <mmontgomery@levado.to> writes:

> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>
>> Meredith Montgomery <mmontgomery@levado.to> writes:
>>
>>> Bart <bc@freeuk.com> writes:
>>>
>>>> On 16/01/2022 02:27, Meredith Montgomery wrote:
>>>>> 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)
>>>>
>>>> Dividing by 10 each time is unnecessary (even if usually optimised to
>>>> shifts and multiplies).
>>>>
>>>> You only need to make this check after you've already processed 19
>>>> characters, as it could overflow on the 20th, but not before.
>>>>
>>>> I think when pos >= 18.
>>>
>>> I suppose you're right, but imagine putting such check there. It would
>>> take even more paragraphs to explain it to myself some time later when
>>> I'm trying to figure out what I wrote a while back.
>>
>> You could just check that the array contains a string of digits
>> lexicographically less than or equal to 18446744073709551615. If there
>> are fewer digits than this, or, at every position, the digit you have is
>> no greater than the corresponding digit of that number, you are ok.
>
> That seems correct, but if I change the size of my register, then I must
> replace the number too. :-)

Sure. Just as you'd have to replace UINT64_MAX and so on. Remember you
don't have to write 18446744073709551615. You could use snprintf to put
UINT64_MAX into a static buffer.

--
Ben.

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

<86bkzt8ls1.fsf@levado.to>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!swDOntj3lPshdK/dkw97wQ.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: Re: on an analogy for verifying whether another digit fits (into an unsigned type)
Date: Sun, 30 Jan 2022 09:12:46 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86bkzt8ls1.fsf@levado.to>
References: <86mtjws9cg.fsf@levado.to> <ss1p1k$shu$1@dont-email.me>
<86k0eyplyy.fsf@levado.to> <87a6fu5l2q.fsf@bsb.me.uk>
<86wnij8hq6.fsf@levado.to> <87k0ejxo7d.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="58594"; posting-host="swDOntj3lPshdK/dkw97wQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:Tan+Xjs9wd0Uc4Tr4IZn4PGwVcA=
 by: Meredith Montgomery - Sun, 30 Jan 2022 12:12 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> Meredith Montgomery <mmontgomery@levado.to> writes:
>
>> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>
>>> Meredith Montgomery <mmontgomery@levado.to> writes:
>>>
>>>> Bart <bc@freeuk.com> writes:
>>>>
>>>>> On 16/01/2022 02:27, Meredith Montgomery wrote:
>>>>>> 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)
>>>>>
>>>>> Dividing by 10 each time is unnecessary (even if usually optimised to
>>>>> shifts and multiplies).
>>>>>
>>>>> You only need to make this check after you've already processed 19
>>>>> characters, as it could overflow on the 20th, but not before.
>>>>>
>>>>> I think when pos >= 18.
>>>>
>>>> I suppose you're right, but imagine putting such check there. It would
>>>> take even more paragraphs to explain it to myself some time later when
>>>> I'm trying to figure out what I wrote a while back.
>>>
>>> You could just check that the array contains a string of digits
>>> lexicographically less than or equal to 18446744073709551615. If there
>>> are fewer digits than this, or, at every position, the digit you have is
>>> no greater than the corresponding digit of that number, you are ok.
>>
>> That seems correct, but if I change the size of my register, then I must
>> replace the number too. :-)
>
> Sure. Just as you'd have to replace UINT64_MAX and so on. Remember you
> don't have to write 18446744073709551615. You could use snprintf to put
> UINT64_MAX into a static buffer.

Lol. You're totally right. It's totally trivial to solve this problem.
Good to know. I will take notice of this. I value trivial solutions
quite a lot: I had to think hard about that verification and there was
this easy solution on my face all along.

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

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

  copy mid

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

  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: Sun, 30 Jan 2022 15:13:52 +0000
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <87ilu1dznz.fsf@bsb.me.uk>
References: <86mtjws9cg.fsf@levado.to> <ss1p1k$shu$1@dont-email.me>
<86k0eyplyy.fsf@levado.to> <87a6fu5l2q.fsf@bsb.me.uk>
<86wnij8hq6.fsf@levado.to> <87k0ejxo7d.fsf@bsb.me.uk>
<86bkzt8ls1.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="1dbc8256201ba2e23e0efb476fdd0bff";
logging-data="22264"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/saaCnLJNHtyGBWesm4lnvpEoBvz9829o="
Cancel-Lock: sha1:DFbSswPR8mIReOyWVKyyqhGODSw=
sha1:4ABu81modC4QHs/iOpBiMERII70=
X-BSB-Auth: 1.2680f2695a092a801b8f.20220130151352GMT.87ilu1dznz.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 30 Jan 2022 15:13 UTC

Meredith Montgomery <mmontgomery@levado.to> writes:

> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>
>> Meredith Montgomery <mmontgomery@levado.to> writes:
>>
>>> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>>
>>>> Meredith Montgomery <mmontgomery@levado.to> writes:
>>>>
>>>>> Bart <bc@freeuk.com> writes:
>>>>>
>>>>>> On 16/01/2022 02:27, Meredith Montgomery wrote:
>>>>>>> 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)
>>>>>>
>>>>>> Dividing by 10 each time is unnecessary (even if usually optimised to
>>>>>> shifts and multiplies).
>>>>>>
>>>>>> You only need to make this check after you've already processed 19
>>>>>> characters, as it could overflow on the 20th, but not before.
>>>>>>
>>>>>> I think when pos >= 18.
>>>>>
>>>>> I suppose you're right, but imagine putting such check there. It would
>>>>> take even more paragraphs to explain it to myself some time later when
>>>>> I'm trying to figure out what I wrote a while back.
>>>>
>>>> You could just check that the array contains a string of digits
>>>> lexicographically less than or equal to 18446744073709551615. If there
>>>> are fewer digits than this, or, at every position, the digit you have is
>>>> no greater than the corresponding digit of that number, you are ok.
>>>
>>> That seems correct, but if I change the size of my register, then I must
>>> replace the number too. :-)
>>
>> Sure. Just as you'd have to replace UINT64_MAX and so on. Remember you
>> don't have to write 18446744073709551615. You could use snprintf to put
>> UINT64_MAX into a static buffer.
>
> Lol. You're totally right. It's totally trivial to solve this problem.
> Good to know. I will take notice of this. I value trivial solutions
> quite a lot: I had to think hard about that verification and there was
> this easy solution on my face all along.

There may be pitfalls I've not spotted because I've never seen this done
in anyone else's code.

--
Ben.

Pages:123
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor