C optimization breaks algorithm
Posted
by Halpo
on Stack Overflow
See other posts from Stack Overflow
or by Halpo
Published on 2010-04-09T16:31:00Z
Indexed on
2010/04/09
16:33 UTC
Read the original article
Hit count: 232
I am programming an algorithm that contains 4 nested for loops. The problem is at at each level a pointer is updated. The innermost loop only uses 1 of the pointers. The algorithm does a complicated count. When I include a debugging statement that logs the combination of the indexes and the results of the count I get the correct answer. When the debugging statement is omitted, the count is incorrect. The program is compiled with the -O3 option on gcc. Why would this happen?
© Stack Overflow or respective owner