gcc - Iteraion 3u invokes unidenified error -
#include <iostream> int main() { (int = 0; < 4; ++i) std::cout << i*5000000000 << std::endl; }
getting warning gcc whenever seek run this.
:-
warning: iteration 3u invokes undefined behavior [-waggressive-loop-optimizations] std::cout << i*5000000000 << std::endl; whats cause of error?
signed integer overflow (as strictly speaking, there no such thing "unsigned integer overflow") means undefined behaviour. unsigned integers, declared unsigned, shall obey laws of arithmetic modulo 2n n number of bits in value representation of particular size of integer.i suspect it's like: (1) because every iteration of value larger 2 has undefined behavior -> (2) can assume <= 2 optimization purposes -> (3) loop status true -> (4) it's optimized away infinite loop.
what going on case of strength reduction, more specifically, induction variable elimination. compiler eliminates multiplication emitting code instead increments 1e9 each iteration (and changing loop status accordingly). valid optimization under "as if" rule programme not observe difference well-behaving. alas, it's not, , optimization "leaks"
gcc compiler-construction gcc-warning
No comments:
Post a Comment