Mail Archives: djgpp-workers/2004/02/24/17:43:39
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
- Raw text -