Deutsch English Français Italiano |
<20240623121952.00005fa9@yahoo.com> 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: Michael S <already5chosen@yahoo.com> Newsgroups: comp.lang.c Subject: Re: The difference between strtol() and strtoul() ? Date: Sun, 23 Jun 2024 12:19:52 +0300 Organization: A noiseless patient Spider Lines: 51 Message-ID: <20240623121952.00005fa9@yahoo.com> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Date: Sun, 23 Jun 2024 11:19:34 +0200 (CEST) Injection-Info: dont-email.me; posting-host="f22476cdd10c6459af95a5b40f6471ec"; logging-data="2641519"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19M4cH3unnWOX9tF7cHDaJUpIWQAZXKeMM=" Cancel-Lock: sha1:moULY45fpVzSlHzqYivAabiA6CU= X-Newsreader: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-w64-mingw32) Bytes: 3173 On Fri, 21 Jun 2024 18:15:07 +0100 Ben Bacarisse <ben@bsb.me.uk> wrote: > 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! > In case of strtol, yes. In case of strtoul it also says what value should be returned, but plain reading of cppreference.com text (at least *my* plain reading) does not match observed behaviour. The text on cppreference.com resembles Standard text, but does not match it. Also, at least to me, Standard text itself appear very far from clear and way too open to interpretations. My own interpretation would be that for any negative input strtoul() should return ULONG_MAX and set errno to ERANGE. None of the actual implementation that I tested behaves in this manner. It seems, the problem is of what is considered "range of representable values" for unsigned type is by itself open to interpretations. IMHO, even if in some part of the standard there exists text that clearly states that "range of representable values for unsigned long = [-ULONG_MAX:ULONG_MAX]" it is worth repeating that in the section that defines strtol, because it is at all non-intuitive.