Here is the code snippet I read from google's gflags source code
case FV_INT32: {
const int64 r = strto64(value, &end, base);
if (errno || end != value + strlen(value)) return false; // bad parse
if (static_cast<int32>(r) != r) // worked, but number out of range
return false;
SET_VALUE_AS(int32, static_cast<int32>(r));
return true;
}
and the macros define strto64
// Work properly if either strtoll or strtoq is on this system
#ifdef HAVE_STRTOLL
# define strto64 strtoll
# define strtou64 strtoull
#elif HAVE_STRTOQ
# define strto64 strtoq
# define strtou64 strtouq
#else
// Neither strtoll nor strtoq are defined. I hope strtol works!
# define strto64 strtol
# define strtou64 strtoul
#endif
Clearly, the author prefer strtoll to strtol. According the man page of these two functions, one returns long long int, and the other returns long int. They are all ok if you only want an int32, right?
So what's the difference between those two functions? Why strtoll is preferred?