X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f Message-ID: <403BE07F.178E187E@yahoo.com> Date: Tue, 24 Feb 2004 18:38:39 -0500 From: CBFalconer Organization: Ched Research X-Mailer: Mozilla 4.75 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: djgpp-workers AT delorie DOT com Subject: Re: strtoul bug (was Re: Fibonacci number) 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> <403BD3E2 DOT 90602 AT cyberoptics DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com Eric Rudd wrote: > > 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. After having had various things in the standard pointed out to me, I am of two minds about this. The standard does say that out of range values should return ULONG_MAX and set errno to ERANGE, which the present implementation does not do for negative values. At any rate, I have posted something to c.l.c and to comp.std.c to attempt to resolve this. -- Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT worldnet DOT att DOT net) Available for consulting/temporary embedded and systems. USE worldnet address!