The difference between NOT false and true

I have this piece of code:

if ( ( data.is_err != FALSE ) && ( available != FALSE ) )
    {
        Set_Dtc_TimerChange(DTC_VPOS, +dt_ms);
    }

Why are you using not equal to false and not equal to true? Is there any difference at all?

+4
source share
3 answers

This is a matter of C, not EE, but since C is very close to hardware.

The old definition of C false is 0, while all other values ​​are true, i.e.

if( 0 ){ ... }

will not execute code ... but for example

if( 1 ){ ... }
if( -1 ){ ... }
if( 42 ){ ... }

All will be. Therefore, you can check the true value for equal FALSE (which is defined as 0), but when you want to compare it with true, what value would you use for true? Some say that TRUE should be defined as (! FALSE), but this will give -1, which is true, but not the only one.

, TRUE.

C , TRUE, ( ) 1, ,

int probably( void ){ return 42; }
if( probably() ){ ... }
if( probably() == TRUE ){ ... }

probbaly(), .

if ( data.is_err && available ) { ... }

, , .

(, - ?)

+11

:

if (  data.is_err &&  available ) { 
    Set_Dtc_TimerChange(DTC_VPOS, +dt_ms); 
}

FALSE - - . , .

+8

C . 0 false true. , , , true. , C: if (x) ... . , , , , . , x != FALSE - , : if ((x != FALSE) != FALSE)....

+1

Source: https://habr.com/ru/post/1606980/


All Articles