One of clients to whom we provided with source code said that by changing int to long and atoi to atol, they get different result of our program. But as far as I understand, int and long on Windows have the same 4 byte size and the same min/max. In the same analogy, I expected atoi and atol produce same output and with our testing, they do.
Is there any difference between those commands I didn’t know?
In non-error cases, the functions are both defined equivalent to
the only difference is that
atoicasts the return value toint.There could be different behavior in error cases (when the string represents a value that is out of range of the type), since behavior is undefined for both. But I’d be surprised. Even if
atoiandatolaren’t implemented by callingstrtol, they’re probably implemented by the same code or very similar.Personally I’d ask that the client show me the exact code. Maybe they didn’t just replace
int->longandatoi->atolas they claim. If that is all they changed (but they did so slightly differently from how you assumed when you did your tests), probably they’ve found the symptom of a bug in your code.