The expression ((FIO2PIN & 0x00001000)>>12)
is an integer expression and is implicitly cast to a boolean by the if(...)
, where zero is false and non-zero is true.
There is nothing wrong with that in the sense that it is entirely unambiguous as far as the compiler and language definition are concerned, but I prefer to use only explicitly boolean expressions in conditional statements - in order to make the intent of the programmer clear. That is easily done by explicitly comparing the result with zero; in this case:
if( ((FIO2PIN & 0x00001000) >> 12) != 0 )
However, the shift is entirely unnecessary in either case, because any non-zero value will be accepted as true (which is why you should always compare with zero - or nothing at all). So:
if( FIO2PIN & 0x00001000 )
or
if( (FIO2PIN & 0x00001000) != 0 )
are equally valid - the latter being my preference.
As mentioned, any non-zero value will be accepted as true while only zero is false, so where x
is an integer expression, the test x == 1
is a dangerous one, and you should use x != 0
instead.