So, this is confusion from bad documentation
Because, my crappy source says,
"
Parameters
str
C-string beginning with the representation of an integral number.
endptr
Reference to an object of type char*, whose value is set by the function
to the next character in str after the numerical value.
This parameter can also be a null pointer, in which case it is not used.
base
Numerical base (radix) that determines the valid characters and their
interpretation.
If this is 0, the base used is determined by the format in the sequence
(see strtol for details).
"
Which makes no mention of the second param being used to indicate an
error condition.
So, I went and got hold of a man page:
"If endptr is not NULL, strtol() stores the address of the first invalid
character in *endptr. If there were no digits at all, however,
strtol()
stores the original value of str in *endptr. (Thus, if *str is
not `\0'
but **endptr is `\0' on return, the entire string was valid.)"
I still fail to see why anyone wants to use this rather than a stream or
a lexical_cast. It's so C90.
Is the preference due to performance, plain hatred of streams, or
something else?
In my tests, the performance really wasn't that much different. Of
course, one could argue whether or not my performance test is written
properly for such an exercise. But I doubt its going to make more than a
microsecond of difference.
I am really not exaggerating when I speak of debugging the
aforementioned scenario over and over again. Bad programmers or not,
they don't seem to make such a mistake when told to use a stream or
lexical cast instead. We're gonna have to work with bad programmers in
most cases.