R
Richard Heathfield
Vladimir S. Oka said:
4.10.1 String conversion functions
The functions atof , atoi , and atol need not affect the value of
the integer expression errno on an error. If the value of the result
cannot be represented, the behavior is undefined.
Now, how do you represent "the value of the result" if the call looks like
this?
int greeting = atoi("Hello, world!");
Whether this is an error would appear to depend on how "error" is defined
with respect to strtol - and the Standard doesn't even /use/ the word
"error" in the strtol section.
Having said that, the strtol section does explain that "Hello, world!" would
be parsed with an empty "subject sequence" (if the base is 10, as it would
be in this case), and 0 is returned.
So I guess it all depends on what you mean - or rather, what the Standard
means - by "error".
Is my reading of the Standrad correct in the sense that the error
return of `atoi` and friends is actually not specified (apart from
saying that it may differ from `strtoul`)?
4.10.1 String conversion functions
The functions atof , atoi , and atol need not affect the value of
the integer expression errno on an error. If the value of the result
cannot be represented, the behavior is undefined.
Now, how do you represent "the value of the result" if the call looks like
this?
int greeting = atoi("Hello, world!");
Whether this is an error would appear to depend on how "error" is defined
with respect to strtol - and the Standard doesn't even /use/ the word
"error" in the strtol section.
Having said that, the strtol section does explain that "Hello, world!" would
be parsed with an empty "subject sequence" (if the base is 10, as it would
be in this case), and 0 is returned.
So I guess it all depends on what you mean - or rather, what the Standard
means - by "error".