In said:
It still seems rather strange to me that strtoul() accepts "-2" and
returns 4294967294 without complaint, but according to the man page it
is supposed to do so.
According to my reading of the C standard it isn't supposed to do so:
Returns
8 The strtol, strtoll, strtoul, and strtoull functions return
the converted value, if any. If no conversion could be performed,
zero is returned. If the correct value is outside the range of
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
representable values, LONG_MIN, LONG_MAX, LLONG_MIN, LLONG_MAX,
^^^^^^^^^^^^^^^^^^^^
ULONG_MAX, or ULLONG_MAX is returned (according to the return
type and sign of the value, if any), and the value of the macro
ERANGE is stored in errno.
Unless I'm missing something, -2 is outside the range of values that can
be represented by unsigned long. And any argument about "folding" it into
range would equally apply to values above ULONG_MAX, so this function
should NEVER set errno to ERANGE if that argument applied.
However, I know, from past discussions, that committee members disagree
with my interpretation.
Dan