7 ms·
Does gcc make any kind of assumptions about signed-overflow? For example, would it eliminate the comparison in this code: int8_t i; /* ... */ i += 1;
by ghswa 13y ago
Does gcc make any kind of assumptions about signed-overflow? For example, would it eliminate the comparison in this code:
int8_t i;
/* ... */
i += 1;
if (i == 0) {
/* ... */
}
- vinkelhake 13y agoYes, it'll exploit the fact that signed overflow is undefined. int incr(int i) { int old = i; i += 1; if (i < old) return 1; return 0; } GCC optimizes this to 'return 0;'. EDIT: Updated to a better example.