X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f Date: Tue, 24 Feb 2004 16:44:50 -0600 From: Eric Rudd Subject: Re: strtoul bug (was Re: Fibonacci number) In-reply-to: <403ADB4A.ED9F77C2@yahoo.com> To: djgpp-workers AT delorie DOT com Message-id: <403BD3E2.90602@cyberoptics.com> Organization: CyberOptics MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7bit X-Accept-Language: en,pdf User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.5) Gecko/20030925 References: <4038E8CA DOT 6491815E AT virginia DOT edu> <4039DD96 DOT 3F36F3B7 AT yahoo DOT com> <200402231458 DOT i1NEwKwm020904 AT envy DOT delorie DOT com> <403A301C DOT E8F5FE65 AT yahoo DOT com> <200402231751 DOT i1NHp5lv022894 AT envy DOT delorie DOT com> <403A5F55 DOT 7E608910 AT yahoo DOT com> <200402232034 DOT i1NKYqrt024366 AT envy DOT delorie DOT com> <403ADB4A DOT ED9F77C2 AT yahoo DOT com> X-MailScanner-Information: Please contact the ISP for more information X-MailScanner: Found to be clean Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk CBFalconer wrote: >First I think we need a consensus as to what is in error. I have >posted something very similar to c.l.c and c.std.c to see what >appears. I still consider the acceptance of signs in the unsigned >varieties to be an error, > 7.20.1.4, paragraph 3 in the C99 standard specifies the convertible part of the input string to consist of "a sequence of letters and digits...optionally preceded by a plus or minus sign", so signs appear to be acceptable. Even if the objection is made that strtoul("-1", NULL, 10) doesn't lie within the representable range of an unsigned long, then the value of strtoul("-0", NULL, 10) surely does, in spite of its minus sign. For me, the question whose answer is most unclear is about the proper thing to do when the string represents a number that is out of range. From a reading of 7.20.1.4, it appears to me that ULONG_MAX should be returned, regardless of whether the number was out of range in the positive or negative direction, and regardless of how far, but I'm by no means sure of that. Thus, the present strtoul() is correct for an input string of "-1", but it appears to treat other negative constants as if they were first converted to a signed long and then to an unsigned long, which I think is incorrect. -Eric Rudd