Z
zl2k
hi, all
I am not sure of this question is suitable for the c++ language group
but still hope the experts here can give me some hints.
I am using gcc 3.4.4 in fc3 and got a very strang error when using
optimization O2 or O3 (the program runs fine if not using
optimization).
Very strange, I can avoid the error by writing in this way:
unsinged long a;
.....
func(const unsigned long a){
if (a == 123){
code_A
}
else{
code_A
}
}
code_A is a block of code which will add a into a STL vector under
certain conditions. As you can see, the if...else is totally noncensse
since both code_A are exactly the same. However, if I don't write in
this way, for example
unsigned long a;
....
func(const unsigned long a){
code_A
}
the gcc optimization will add a different number other than "123" to
the vector sometimes and I am not able to track the error using DDD.
The break point won't break at where it is set!
I found the problem that sometimes the value added into the vector is
not what I expected, say, I got "456" when I tried to add "123". Then I
tried to debug the block of code_A to see what's going on if "123" is
added. So I use the if...else. The bug dissapper just by adding the
if...else. Is gcc -O2 usuable? What the problem is that?
Thanks for help.
zl2k
I am not sure of this question is suitable for the c++ language group
but still hope the experts here can give me some hints.
I am using gcc 3.4.4 in fc3 and got a very strang error when using
optimization O2 or O3 (the program runs fine if not using
optimization).
Very strange, I can avoid the error by writing in this way:
unsinged long a;
.....
func(const unsigned long a){
if (a == 123){
code_A
}
else{
code_A
}
}
code_A is a block of code which will add a into a STL vector under
certain conditions. As you can see, the if...else is totally noncensse
since both code_A are exactly the same. However, if I don't write in
this way, for example
unsigned long a;
....
func(const unsigned long a){
code_A
}
the gcc optimization will add a different number other than "123" to
the vector sometimes and I am not able to track the error using DDD.
The break point won't break at where it is set!
I found the problem that sometimes the value added into the vector is
not what I expected, say, I got "456" when I tried to add "123". Then I
tried to debug the block of code_A to see what's going on if "123" is
added. So I use the if...else. The bug dissapper just by adding the
if...else. Is gcc -O2 usuable? What the problem is that?
Thanks for help.
zl2k