4 ms·
for (size_t i = numBurritos - 1; i != -1; i--) This will fail on a platform where sizeof(size_t) < sizeof(int). I admit that I don't know of any such platform
by cperciva 11y ago
for (size_t i = numBurritos - 1; i != -1; i--)
This will fail on a platform where sizeof(size_t) < sizeof(int). I admit that I don't know of any such platform, but I can't see any reason why it wouldn't be possible.
A better way to write this is
for (size_t i = numBurritos - 1; i < numBurritos; i--)
- phkahler 11y agoI seriously wonder what's wrong with using an int and the original count down construct. You have to think about it on 16 or 32 bit platforms, but this statement from the link: >> Especially consider the case of an index into a string (char *) on a 64 bit platform. size_t is the appropriate type for an index because the limited range of int is not nearly enough. That's just bull in most applications. Even if you could run 1 trillion iterations per second, the loop would take 2^23 seconds to complete or about 97 days. In general if you're not doing "big data" and int will index an array just fine thank you. And that's indexing bytes, it should index any other type just fine in any case - assuming of course that a pointer and int are the same size.
- cperciva 11y agoMany 64-bit platforms have 32-bit int.