Re: The difference between strtol() and strtoul() ?

Liste des GroupesRevenir à cl c  
Sujet : Re: The difference between strtol() and strtoul() ?
De : ben (at) *nospam* bsb.me.uk (Ben Bacarisse)
Groupes : comp.lang.c
Date : 23. Jun 2024, 13:38:51
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <87r0cnq46s.fsf@bsb.me.uk>
References : 1 2 3 4 5 6
User-Agent : Gnus/5.13 (Gnus v5.13)
Michael S <already5chosen@yahoo.com> writes:

On Fri, 21 Jun 2024 18:15:07 +0100
Ben Bacarisse <ben@bsb.me.uk> wrote:
>
Michael S <already5chosen@yahoo.com> writes:
 
On Fri, 21 Jun 2024 18:28:39 +0300
Michael S <already5chosen@yahoo.com> wrote:
 
On Fri, 21 Jun 2024 13:58:01 -0000 (UTC)
gazelle@shell.xmission.com (Kenny McCormack) wrote: 
 
Yeah, now I get it.  You really only need strtoimax() and
strtoumax().  
 
Which are? uunfortunately, not part of C standard.
 
A result of any smaller type can be obtained by calling one of
these functions and storing the result in an object of the
smaller type.
 
Or check for range and handle out of range values as appropriate by
situation. 
>
BTW, I don't know what The Standard says about out-of-range inputs,
but at least https://en.cppreference.com/w/c/string/byte/strtol
does not say anything certain. especially about what stored in
*str_end. 
 
It says what value should be returned.  That's something certain!
>
>
In case of strtol, yes.
In case of strtoul it also says what value should be returned, but
plain reading of cppreference.com text (at least *my* plain reading)
does not match observed behaviour. The text on cppreference.com
resembles Standard text, but does not match it.

Ah.  What's the discrepancy you see?

Also, at least to me, Standard text itself appear very far from clear
and way too open to interpretations.
My own interpretation would be that for any negative input strtoul()
should return ULONG_MAX and set errno to ERANGE. None of the actual
implementation that I tested behaves in this manner.

I don't get that from the text.  There is, after all, no "negative
input".  There is a "subject sequence" which, if it starts with a minus
sign, causes the "value resulting from the conversion is negated (in the
return type)" which seems clear enough.

It seems, the problem is of what is considered "range of representable
 values" for unsigned type is by itself open to interpretations.
>
IMHO, even if in some part of the standard  there exists text that
clearly states that "range of representable values for unsigned long =
[-ULONG_MAX:ULONG_MAX]" it is worth repeating that in the section that
defines strtol, because it is at all non-intuitive.

I don't get what you are saying here.  The range of values is [0:ULONG_MAX].

--
Ben.

Date Sujet#  Auteur
20 Jun 24 * The difference between strtol() and strtoul() ?45Kenny McCormack
20 Jun 24 +- Re: The difference between strtol() and strtoul() ?1Lew Pitcher
20 Jun 24 +- Re: The difference between strtol() and strtoul() ?1Lew Pitcher
20 Jun 24 +- Re: The difference between strtol() and strtoul() ?1Keith Thompson
21 Jun 24 +* Re: The difference between strtol() and strtoul() ?2Kaz Kylheku
21 Jun 24 i`- Re: The difference between strtol() and strtoul() ?1Kenny McCormack
21 Jun 24 +* Re: The difference between strtol() and strtoul() ?38Kenny McCormack
21 Jun 24 i+* Re: The difference between strtol() and strtoul() ?34Michael S
21 Jun 24 ii+* Re: The difference between strtol() and strtoul() ?27Michael S
21 Jun 24 iii+* Re: The difference between strtol() and strtoul() ?19Ben Bacarisse
23 Jun 24 iiii`* Re: The difference between strtol() and strtoul() ?18Michael S
23 Jun 24 iiii `* Re: The difference between strtol() and strtoul() ?17Ben Bacarisse
23 Jun 24 iiii  `* Re: The difference between strtol() and strtoul() ?16Michael S
23 Jun 24 iiii   `* Re: The difference between strtol() and strtoul() ?15Ben Bacarisse
23 Jun 24 iiii    +- Re: The difference between strtol() and strtoul() ?1Michael S
23 Jun 24 iiii    +* Re: The difference between strtol() and strtoul() ?12Tim Rentsch
24 Jun 24 iiii    i+* Re: The difference between strtol() and strtoul() ?10Keith Thompson
24 Jun 24 iiii    ii+* Re: The difference between strtol() and strtoul() ?8Ben Bacarisse
24 Jun 24 iiii    iii+- Re: The difference between strtol() and strtoul() ?1Keith Thompson
24 Jun 24 iiii    iii`* Re: The difference between strtol() and strtoul() ?6Kaz Kylheku
24 Jun 24 iiii    iii +* Re: The difference between strtol() and strtoul() ?3Kaz Kylheku
24 Jun 24 iiii    iii i`* Re: The difference between strtol() and strtoul() ?2Keith Thompson
24 Jun 24 iiii    iii i `- Re: The difference between strtol() and strtoul() ?1Kaz Kylheku
24 Jun 24 iiii    iii `* Re: The difference between strtol() and strtoul() ?2Keith Thompson
24 Jun 24 iiii    iii  `- Re: The difference between strtol() and strtoul() ?1Michael S
24 Jun 24 iiii    ii`- Re: The difference between strtol() and strtoul() ?1Tim Rentsch
24 Jun 24 iiii    i`- Re: The difference between strtol() and strtoul() ?1Tim Rentsch
24 Jun 24 iiii    `- Re: The difference between strtol() and strtoul() ?1Lawrence D'Oliveiro
21 Jun 24 iii+* Re: The difference between strtol() and strtoul() ?4James Kuyper
21 Jun 24 iiii+* Re: The difference between strtol() and strtoul() ?2Kenny McCormack
23 Jun 24 iiiii`- Re: The difference between strtol() and strtoul() ?1Michael S
22 Jun 24 iiii`- Re: The difference between strtol() and strtoul() ?1Michael S
22 Jun 24 iii`* Re: The difference between strtol() and strtoul() ?3Lawrence D'Oliveiro
23 Jun 24 iii +- Re: The difference between strtol() and strtoul() ?1Lawrence D'Oliveiro
23 Jun 24 iii `- Re: The difference between strtol() and strtoul() ?1James Kuyper
21 Jun 24 ii`* Re: The difference between strtol() and strtoul() ?6Ben Bacarisse
21 Jun 24 ii `* Re: The difference between strtol() and strtoul() ?5Keith Thompson
22 Jun 24 ii  +- Re: The difference between strtol() and strtoul() ?1Lawrence D'Oliveiro
22 Jun 24 ii  `* Re: The difference between strtol() and strtoul() ?3Michael S
23 Jun 24 ii   +- Re: The difference between strtol() and strtoul() ?1Lawrence D'Oliveiro
23 Jun 24 ii   `- Re: The difference between strtol() and strtoul() ?1Keith Thompson
21 Jun 24 i+* Re: The difference between strtol() and strtoul() ?2Michael S
21 Jun 24 ii`- Re: The difference between strtol() and strtoul() ?1Keith Thompson
23 Jun 24 i`- Re: The difference between strtol() and strtoul() ?1Kaz Kylheku
23 Jun 24 `- Re: The difference between strtol() and strtoul() ?1Richard Kettlewell

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal