4 ms·
Great, and what happens when you accidentally assign something greater than 2^31 to an int32_t when using strtol? You won't benefit from a range error if LONG_M
by ihattendorf 5y ago
Great, and what happens when you accidentally assign something greater than 2^31 to an int32_t when using strtol? You won't benefit from a range error if LONG_MAX is 2^63, and now you have to make sure to handle any implementation defined behavior.
- foxfluff 5y agoThat's true. If the range you're interested in is not the same as the range of long or long long, you'll have to check the range yourself before you go on and use the value. No ifdefs required. If you're not happy doing it yourself, I do recommend strtonum or any of the alternatives that allow you to explicitly specify the range you're interested in. I don't see the point in littering the standard library with functions having hard-coded range for every range you might be interested in.