I have written an if-clause that checks whether I should break the program for debugging or not:
if (a < 0) {
a = a;
}
a should not become negative, but I have found that it does, and I want to break for debugging to see why it becomes negative if that happens, hence I have written this if-clause. On the line a = a; I have set a breakpoint, which is supposed to stop the program if it enters the if-clause. The thing is that the line doesn't do anything (which is necessary in order not to mess anything up), so the line is optimized away and the breakpoint ends up after the if-clause. This trick usually works but apparently the compiler wasn't very found of it this time.
The language is C++, and I'm compiling with qmake (a Qt tool) and mingw.
My question is, how can I prevent the compiler from optimizing away lines of code when I have breakpoints set on them? Or is there some other way to conditionally break the program for debugging?
mingw, using the Qt toolqmake(I updated my question). I just saw your question now but I have already solved the problem (see accepted answer). - HelloGoodbye