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 22:30:35 -0700 Organization: A noiseless patient Spider Lines: 27 Message-ID: <86msnagb5w.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> <864j9jh77d.fsf@linuxsc.com> <87r0cntga9.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Mon, 24 Jun 2024 07:30:35 +0200 (CEST) Injection-Info: dont-email.me; posting-host="b3b1304951eae8dc1e53ef86c96f1e35"; logging-data="841669"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fDfEk89jrBdMYkoaS079djRtwe0bk7Mo=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:Cwy4VKUVRKIRWMVfa5VUMbFH9KI= sha1:bRit3OyOhxKced03zuR8bodR5JY= Xref: csiph.com comp.lang.c:386437 Keith Thompson writes: > Tim Rentsch writes: > >> 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. > > Can you give an example where the specified behavior causes undefined > behavior? Ben gave a good answer. (My thanks to Ben for both the content and the style of his answer.)