Deutsch English Français Italiano |
<87o77rnrt2.fsf@bsb.me.uk> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse <ben@bsb.me.uk> Newsgroups: comp.lang.c Subject: Re: The difference between strtol() and strtoul() ? Date: Mon, 24 Jun 2024 00:49:13 +0100 Organization: A noiseless patient Spider Lines: 36 Message-ID: <87o77rnrt2.fsf@bsb.me.uk> References: <v51d1l$2fklr$1@news.xmission.com> <v540t9$2gsdu$1@news.xmission.com> <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 Injection-Date: Mon, 24 Jun 2024 01:49:13 +0200 (CEST) Injection-Info: dont-email.me; posting-host="2fe2b5b522b691828527b639c59887b1"; logging-data="606629"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18btkKvjoUbOCZp2Zb+mHQdiCOskzk7emM=" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:mUpjazRxS1NRgRcnqjOx7IPN2Bs= sha1:u9WGwzUFCGQsiWdR2X6f27RG0vc= X-BSB-Auth: 1.0db0316267d871dc09d5.20240624004913BST.87o77rnrt2.fsf@bsb.me.uk Bytes: 2921 Keith Thompson <Keith.S.Thompson+u@gmail.com> writes: > Tim Rentsch <tr.17687@z991.linuxsc.com> writes: >> Ben Bacarisse <ben@bsb.me.uk> 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? 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"? -- Ben.