2 ms·
"long" is not guaranteed to be larger than "int", and in fact it isn't on 64-bit Windows. (Let alone 32-bit platforms in general.) https://en.wikipedia.org/wik
by eqvinox 1y ago
"long" is not guaranteed to be larger than "int", and in fact it isn't on 64-bit Windows. (Let alone 32-bit platforms in general.)
https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_m...
You need to use "long long" or "intmax_t" (and matching strtoll/strtoimax)
- rantouan 1y agooverflow problems, which I try to avoid, start only if its bigger than int. So I had assumed that in my case I'm alright. Do you see any change needed that I can't see ? --- Maybe a good idea would had been to go by platform or architecture and use some macros to do the check only if it's really needed. What do you think of it ? How would you implement it ? You can make a pull request as well.
- deleted 1y ago[deleted]
- eqvinox 1y agoIf strtol reliably sets errno to ERANGE, you're fine (you'll get a compiler warning for "if (aLong < INT_MIN || aLong > INT_MAX) {" though, because it can never be true.) I have no idea what the cross-platform reliability of strtol() is, regarding errno. Should be fine, I hope.