[opensource] uint64_t Question

Shaun Rowland rowland at cse.ohio-state.edu
Mon May 21 13:01:36 EDT 2007


Evan Powers wrote:

> I would avoid atoi()/strtol() and variants thereof, because there's no
> way for them to signal a conversion error. I also wouldn't use
> iostream; it's just too painful.

That's not true for strtol, and variants. It is true for atoi. The Linux
implementation will give EINVAL if there is a conversion error, but this
is not C99. There is also ERANGE, which is C99. In addition to this, you
can check the pointers to see if there were any invalid characters that
could not be converted, thus EINVAL is not really necessary - and I
would not use it because it is not everywhere. If everything was
converted by pointer checks, and there was no error code, then there was
no conversion error. Details are in the manual page.

I've used input methods to convert before, but I tend to try and use
conversion functions if possible.
-- 
Shaun Rowland	rowland at cse.ohio-state.edu
http://www.cse.ohio-state.edu/~rowland/


More information about the Opensource mailing list