I
Ivan Shmakov
[Cross-posting to for strtoul () is part of
ISO C.]
Curiously enough, I've always tested for failure with
(*endptr == str) after the call. To my mind, it aligns better
with the calling conventions of other functions, where one
checks the return value for failure first, and checks errno for
the cause if necessary afterwards.
--cut: http://pubs.opengroup.org/onlinepubs/9699919799/functions/strtoul.html --
If the subject sequence is empty or does not have the expected form,
no conversion shall be performed; the value of str shall be stored
in the object pointed to by endptr, provided that endptr is not a
null pointer.
--cut: http://pubs.opengroup.org/onlinepubs/9699919799/functions/strtoul.html --
ISO C.]
Incorrect. There are a number of POSIX defined calls where you
_must_ clear errno prior to the call in order to detect that an error
occurred during the call (strtoul, for example).
Curiously enough, I've always tested for failure with
(*endptr == str) after the call. To my mind, it aligns better
with the calling conventions of other functions, where one
checks the return value for failure first, and checks errno for
the cause if necessary afterwards.
--cut: http://pubs.opengroup.org/onlinepubs/9699919799/functions/strtoul.html --
If the subject sequence is empty or does not have the expected form,
no conversion shall be performed; the value of str shall be stored
in the object pointed to by endptr, provided that endptr is not a
null pointer.
--cut: http://pubs.opengroup.org/onlinepubs/9699919799/functions/strtoul.html --