Sujet : Re: The difference between strtol() and strtoul() ?
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 24. Jun 2024, 03:29:19
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240623191452.334@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-06-23, Ben Bacarisse <
ben@bsb.me.uk> wrote:
I don't want to pre-empt Tim's answer, but the wording that bothers me
is
>
"If the subject sequence begins with a minus sign, the value
resulting from the conversion is negated (in the return type)."
>
For strtoll("-9223372036854775808", 0, 0) the value resulting from the
conversion is 9223372036854775808 which can not even be represented in
the return type, so how can it be negated "in the return type"?
We have to trust that the specification wants the functions to perform
error checking, rather than precipitate into undefined behavior or
implementation-defined results.
If the negation, which is a positive value, cannot be represented in the
type, that implies it is out of range. The required behavior for a
positive out-of-range value is to return LLONG_MAX and set errno to
ERANGE.
The "in the return type" wording sounds like it may be written that way
to cover the unsigned case, strtoull.
I see in the N3220 draft that the signed and unsigned functions are
lumped together and the wording is now:
"If the subject sequence begins with a minus sign, the resulting value
is the negative of the converted value; for functions whose return type
is an unsigned integer type this action is performed in the return
type."
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca