Path: csiph.com!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: The difference between strtol() and strtoul() ?
Date: Sun, 23 Jun 2024 10:58:30 -0700
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <864j9jh77d.fsf@linuxsc.com>
References: <20240621182839.00000dc4@yahoo.com> <20240621185314.00004fda@yahoo.com> <87o77uqktg.fsf@bsb.me.uk> <20240623121952.00005fa9@yahoo.com> <87r0cnq46s.fsf@bsb.me.uk> <20240623153219.000009b0@yahoo.com> <87jzifpth6.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Sun, 23 Jun 2024 19:58:31 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="0b6502de53f4a38a6a5d9b1aa17823cb"; logging-data="464194"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18DgpPJBAB9LU2hwM7g+xiMvlLW2mOGJD8="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:KUJ1omnBAsNBi31UJv2I8FHnU+w= sha1:ZjJ8KetCc30MdGQqSf8s+7/Xx9Q=
Xref: csiph.com comp.lang.c:386396
Ben Bacarisse writes:
[range questions for strtol(), etc]
> I think there /is/ something problematic with the wording about the
> negation. It happens "in the return type" but how can
> 9223372036854775808 be negated in the type long long int? OK, the
> negated value can be /represented/ in the type long long int but that's
> not quite the same thing. On the othee hand, for the unsigned return
> types, the negation "in the return type" is what produces ULONG_MAX for
> "-1" when the negated value, -1, can't be /represented/ in the return
> type. It's a case where, over the years, I've just got used to what's
> happening.
I understand what these functions do, but their specification in the
C standard is a little off. To my way of thinking the impact is
minimal, but the specified behavior is either unequivocally wrong or
there are some cases that give rise to undefined behavior.