|
strange effect: if ... else in C influence a previous statement
I write a short code in c
it may work well, but when I add an if ... else ... structure, a computation before the structure can not give a correct result
compilation and run can do well, but the result is wrong. Very strange
(1)
y2 = expression; //y2 = 0 always 0 error
.................
add : if(a->is_root) c = m2 - y2;
else f = m2 - y2;
(2)
y2 = expression; //y2 = 0 always 0 error
.................
add : if(a->is_root) c = m2 - y2;
if(!a->is_root) f = m2 - y2;
(3)
y2 = expression; // y2 = normal value; normal
.................
add : //if(a->is_root) c = m2 - y2;
if(!a->is_root) f = m2 - y2;
(4)
y2 = expression; // y2 = normal value; normal
.................
add : if(a->is_root) c = m2 - y2;
//if(!a->is_root) f = m2 - y2;
(5)
y2 = expression; // y2 = normal value; normal
add : //if(a->is_root) c = m2 - y2;
//if(!a->is_root) f = m2 - y2;
Trouble: can not use if... else ... normally
Question: (1) if... else ... can influence a previous statement, why?
(2) How to solve the problem?
Last edited by cdbug; 11-20-2008 at 05:38 AM..
|