| Deutsch English Français Italiano |
|
<87o77uqktg.fsf@bsb.me.uk> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.mixmin.net!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: Fri, 21 Jun 2024 18:15:07 +0100 Organization: A noiseless patient Spider Lines: 38 Message-ID: <87o77uqktg.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> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Fri, 21 Jun 2024 19:15:07 +0200 (CEST) Injection-Info: dont-email.me; posting-host="779a099c8be26a0eebc6842c027368a0"; logging-data="3427957"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+byMsb3RNvR0elaJNxXoktTWm2AdbPe24=" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:fFgPft+2AgWfsNfHfG2aIsVWYm0= sha1:ElU1jKjhOymeBbOfpq4sY0uiXeI= X-BSB-Auth: 1.78935f3c6b5deb760244.20240621181507BST.87o77uqktg.fsf@bsb.me.uk Bytes: 2632 Michael S <already5chosen@yahoo.com> writes: > 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. >> >> > A result of any smaller type can be obtained by calling one of these >> > functions and storing the result in an object of the smaller type. >> > >> >> Or check for range and handle out of range values as appropriate by >> situation. > > 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. It says what value should be returned. That's something certain! As for what gets put into *str_end that page could be clearer. The standard says that a pointer just past the last of the digits is stored, provided the input has the right form (spaces, sign, prefix, digits). The cppreference page says a pointer just past "the last numeric character interpreted" which begs the question of what "interpreted" means when the result is possibly out of range. Maybe saying "scanned" rather than interpreted would be better. The end pointer always points just past any syntactically valid characters, even when the result is out of range. -- Ben.