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

Liste des GroupesRevenir à cl c  
Sujet : Re: The difference between strtol() and strtoul() ?
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.c
Date : 21. Jun 2024, 20:38:56
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v54hc0$39bpi$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla Thunderbird
On 6/21/24 11:53, Michael S wrote:
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.

They have been part of the C standard since C99.

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.

"The strtoimax and strtoumax functions are equivalent to the strtol,
strtoll, strtoul, and strtoull functions, except that the initial
portion of the string is converted to intmax_t and uintmax_t
representation, respectively." (7.8.2.3p2)

You need to go to the descriptions of those other functions to get the
detailed specifications.

"If the correct value is outside the range of representable values,
LONG_MIN, LONG_MAX, LLONG_MIN, LLONG_MAX, ULONG_MAX, or ULLONG_MAX is
returned (according to the return type and sign of the value, if any),
and the value of the macro ERANGE is stored in errno."

As I understand it, that means that if the input string represents a
value outside of the range of representable values, then strtoimax()
should return INTMAX_MIN or INTMAX_MAX, depending upon the sign, and
strtouimax() should return UINTMAX_MAX. Both of them should store the
value of ERANGE in errno, to distinguish these results from what you
would get if the string happened to represent those values.


The C standard uses end_ptr rather than str_end in it's description of
these functions.

"... First, they decompose the input string into three parts: an
initial, possibly empty, sequence of white-space characters, a subject
sequence resembling an integer represented in some radix determined by
the value of base, and a final string of one or more unrecognized
characters, including the terminating null character of the input
string. ..." (7.21.4.7p2).

That defines what the "final string" is.

"If the subject sequence has the expected form, ... A pointer to the
final string is stored in the object pointed to by endptr, provided that
endptr is not a null pointer." (7.24.1.7p5).

"If the subject sequence is empty or does not have the expected form ...
the value of nptr is stored in the object pointed to by endptr, provided
that endptr is not a null pointer." (7.21.4.7p7)

That seems very precise and unambiguous to me, aside from what "the
expected form" is, which is described elsewhere.

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