Mail Archives: djgpp-workers/2004/02/24/23:20:23
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.
<http://cbfalconer.home.att.net> USE worldnet address!
- Raw text -