Working with an MSP430 design I came across unexpected behavior with some very simple C code.
the original code:
#define INPUT_BIT P1IN & Bit2 //checks input P1 bit 2
...later in the code:
If (INPUT_BIT == 0) input_low(); //CASE #1
else input_high();
The code always executes input_high(). If I change the if statement to read:
if((INPUT_BIT) == 0) input_low(); // CASE #2
then the if statement branches according to the input on bit2 of portA.
Question: Is this a compiler bug?
I would have thought that the compiler after expanding the macro in CASE #1 would get
If ( P1IN & Bit2 == 0) input_low();
which should be evaluated correctly but in CCS V5 the parenthesizes appear to be necessary.
Am I missing something?


