As we know, int16_t has a max value 32767, so the following code will just loop:
for (int16_t i = 0; i < 65535; i++) {
// infinite loop
}
When I change the code, it loops as well:
const int32_t t = 65535;
for (int16_t i = 0; i < t; i++) {
// infinite loop
}
But when I make it uint32_t instead of int32_t, it actually exits:
const uint32_t t = 65535;
for (int16_t i = 0; i < t; i++) {
// actually exits
}
Is this due to some compiler trick it does for me? I assume when I do the comparison:
i < t
For the last version it does auto convert for me? But I don't understand why it exits in the last version still...