Friday, 15 March 2013

c++ - Strange bug that is solved with a cout -


This is the first time that I see a bug like this. I have this function:

  double calce_value (string equation, int degree, four _for) {string monom [100]; Monomial monomial [100]; Double val_sum [100]; Memset (val_sum, 0, sizeof (val_sum)); For (int i = 0; i & lt; count_monom (equation); i ++) {monom [i] = obt_mon_from (equation, i); Monomial [i] = str_to_monomial (for equation, i, monom [i], _); // cout & lt; & Lt; Monopoly [i] .value; If (monomial [i] .member == 2) monomial [i] .value * = -1; Val_sum [monomial [i] .degree] + = monomial [i] .value; } Return val_sum [degree]; }  

This function is part of a program that fixes the equation, if you are surprised. I can not post the whole code because it has about 600 lines, but I'm pretty sure the bug is here (anyway, tell me if you need more).

If I compile the code in this way it gives me a wrong solution, but if I remove cout in line 14 and then compile and run the program then gives me the correct answer.

If I run it in debug mode then gives me correct answer too.

I have done a little research and I think the programmer is called a hegesensburg, but I am not getting it. Can you help me, please?

Anyway, I am using Code :: Blocks and the GCC Compiler.


No comments:

Post a Comment