wired bug using gcc O2

Z

zl2k

hi, all
I got a wired bug when using gcc -O2. In short, I have something like

int a, b;
....
assert(a < b); //line 1
cout<<a<<" "<<b<<endl; //line 2
assert(a < b); //line 3

The program break on line 3. Why not break on line 1 since I did
nothing on line 2 but cout. However, if I put line 2 infront of line 1,
then the program will break on line 1.

Some experts suggests that this is due to the uninitilized variables
dangling arround. I check my constructor and quite sure all the
variables declared in the header file are initialized.

The above problem won't happen if not using the optimization switch. I
am using gcc 3.4.4. Thanks for your comments. How may I nail down the
bug?

zl2k
 
V

Victor Bazarov

zl2k said:
I got a wired bug when using gcc -O2. In short, I have something like

int a, b;
...
assert(a < b); //line 1
cout<<a<<" "<<b<<endl; //line 2
assert(a < b); //line 3

The program break on line 3. Why not break on line 1 since I did
nothing on line 2 but cout. However, if I put line 2 infront of line
1, then the program will break on line 1.

Some experts suggests that this is due to the uninitilized variables
dangling arround. I check my constructor and quite sure all the
variables declared in the header file are initialized.

The above problem won't happen if not using the optimization switch. I
am using gcc 3.4.4. Thanks for your comments. How may I nail down the
bug?

Simple: disable optimizations. Optimizers sometimes produce unstable
code and there is nothing you can do about it. Try reducing the level
of optimization. Try declaring those 'a' and 'b' "volatile".

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top