From the standard 7.21.6.2p10 ( (f)scanf applies to the whole family):
... If this object does not have the appropriate type, or if the result of the conversion cannot be represented in the object, the behavior is undefined .
Looks like another reason to be very careful with the scanf family. The strtoXX functions have fully defined behavior. They return LONG_MAX , etc. For input too large and set errno == ERANGE . Therefore, if you need accurate information, enter the token manually and use these functions to convert. Another advantage: improved error handling.
Olaf Jun 24 '17 at 20:14 2017-06-24 20:14
source share