3 ms·
> Because even something as basic as how large is an int is can quickly lead to a bug when someone assumes the usual rules still apply. Would someone actually
by natesm 15y ago
> Because even something as basic as how large is an int is can quickly lead to a bug when someone assumes the usual rules still apply.
Would someone actually ask this and expect a numerical response? The only correct answer is sizeof(int), right?
- dionidium 15y agoThe sizes of primitives in C are implementation defined, but the sizes of primitives in some other languages (e.g. Java) are defined by the specification.
- natesm 15y agoThat's true, I was purely thinking in C there.
- JoshTriplett 15y agoIn C, it still applies when you use the stdint.h sized types, such as uint32_t and uint64_t.
- JoshTriplett 15y agoThis seems like a case where recognition matters more than memorization. On occasion, it can come in handy to memorize that on most modern 32-bit systems, INT_MAX == 2147483647. More often, it can come in handy to see that number or something close to it pop out in an unexpected place and immediately think "huh, that's (close to) INT_MAX". The same thing applies to 4294967295, 1048576, 65536, and the ASCII codes of various common characters.