Some examples
Marcus Gruendler
runner at pool.informatik.rwth-aachen.de
Fri Sep 3 13:20:14 BST 1999
On Fri, 03 Sep 1999, Jacek Wojdel wrote:
[...]
> Hi,
>I'm using GNU g++ version 2.95.1 and GNU gdb version 4.18 on Solaris machine. I
>decided just to test if you're right, so I wrote the following program:
> 1- #include <stdio.h>
> 2-
> 3- void main()
> 4- {
> 5- int d = 0;
> 6- for (int i = 0; i < 100; i++ )
> 7- {
> 8- printf("%d\n", d);
> 9- d++;
>10- }
>11- }
>
>I compiled it with options -g3 -O3 and started debugger (at work I use XEmacs
>as a front-end, but this shoudn't matter to the way the gdb works). When doing
>step-by-step execution the line number 9 is never visited. Even if you set the
>breakpoint on that line, the execution will stop at line 10. When compiling
>with -O0, the line #9 is normally visited. Of course for some more complicated
>programs the results of optimizations can be more "twisted" which results in
>seemingly random jumping over some statements. If you really don't experience
This behaviour is absolutely normal. the "-O3" compiler option sais that the
compiler optimizes the assembler code it produces. In this case the source line
numbers do not necessarily correspondent anymore with the intructions executed.
If you don't want that behaviour, use the "-O0" switch, which means that there
is no optimization and everything is as you want ;-). You should use
optimization only if you want to release your program.
Have fun, Marcus
--
Marcus Gruendler runner at pool.informatik.rwth-aachen.de
http://www-users.rwth-aachen.de/Marcus.Gruendler/index_en.html
More information about the KDevelop
mailing list