The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 11-20-2008
cdbug cdbug is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 52
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..