Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!csc.ti.com!ti-csl!m2.csc.ti.com!m2!gafter From: gafter@m2.csc.ti.com (Neal M Gafter) Newsgroups: comp.std.c Subject: strtoul("-10", ...) Message-ID: Date: 24 Jul 90 21:39:28 GMT Sender: gafter@csc.ti.com (Neal M Gafter) Reply-To: (Neal M Gafter) Distribution: comp Organization: TI Computer Science Center, Dallas Lines: 39 I have implemented the ANSI library function strtoul() [4.10.1.6] and had a little problem interpreting the standard. To quote: If the subject sequence begins with a minus sign, the value resulting from the conversion is negated. and If the correct value is outside the range of representable values, ULONG_MAX is returned, and the value of the macro ERANGE is stored in errno. My question is: what is the `range of representable values'? Unsigned longs can represent values in the range [0..ULONG_MAX]. Alternately, one might argue that any integer is representable as an unsigned long, since unsigneds operate in modular arithmetic. This latter possibility would imply that the macro errno is never set to ERANGE. Discounting the possibility that X3J11 intended errno never to be set to ERANGE by strtoul(), I assumed X3J11 meant the range [0..ULONG_MAX]. I presumed the sentence about the minus sign was to allow the string "-0" and to recognize (as errors) other negative numbers. Thus, I assumed any string representing a negative number should cause errno to be set to ERANGE and strtoul() to return ULONG_MAX. I talked to two different X3J11 committee members to confirm my interpretation. To my surprise, I got two different answers, both different from mine. One suggested the range [-ULONG_MAX..ULONG_MAX] be allowed, the other suggested [LONG_MIN..ULONG_MAX], in both cases with the returned result being computed using modular arithmetic. Can the committee please create a definitive interpretation? -- Arpa: gafter@csc.ti.com (Neal Gafter) USnail: Texas Instruments MS 238, PO BOX 655474, Dallas, TX 75265 phone: (214) 995 - 0696 (office) or (214) 727 - 2082 (home) -- Arpa: gafter@csc.ti.com (Neal Gafter) USnail: Texas Instruments MS 238, PO BOX 655474, Dallas, TX 75265 phone: (214) 995 - 0696 (office) or (214) 727 - 2082 (home)