Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

How does the compiler interpret uncasted situation?

$
0
0

Hello,

How does the compiler interpret the "if" statement below when Tsop_Latched_Val = 0 and

Gated_Range_Front_Snsr = 0?

I used no casts here on either variables and the compiler still recognizes that the TsopLatched_Val is greater than (Gate_Range_Front_Snsr - 40) ??? Should I cast the Gated_Range_Front_Snsr from float to unsigned char??? like this:

if( Tsop_Latched_Val >= (unsigned char) (Gated_Range_Front_Snsr - 40)){ bla... bla...}

But then this would make no sense as how can the compiler compare two unsigned chars when one is negative???

unsigned char Tsop_Latched_Val = 0;
float Gated_Range_Front_Snsr = 0;

// bla bla ...

if(Tsop_Latched_Val >= (Gated_Range_Front_Snsr - 40.0)){

// bla bla ...
} 

confused!

r


Viewing all articles
Browse latest Browse all 15302

Trending Articles