I am using MISRA C 2004 standards in Code Composer Studio. I am always getting errors with respect to bitwise operations during initialization of the peripherals.
In the compiler .h file, the definition is like this.
#define SFR_8BIT(addr) extern volatile unsigned char addr
SFR_8BIT(REG1);
#define REG2 REG1
Now in my code, if I use
REG2 |= 0x01;
The MISRA C is popping out these errors:
Bitwise operators shall not be applied to operands whose underlying type is signed – #1393-D (MISRA-C:2004 10.1/R)
The value of an expression of integer type shall not be implicitly converted to a different underlying type if it is not a conversion to a integer type of the same signedness.
I don’t want to change the compiler .h file, and I want to eradicate these warnings.
At a guess, your
charis 8 bits andintis (at least) 16. That means all values ofunsigned charcan be represented as (signed)ints. That, in turn, means in your expressionREG2 |= 0x01;, yourunsigned charwill be promoted toint, then theORoperation carried out, then the result of that cast back tounsigned char.If I’m not mistaken, changing your constant to an
unsigned charshould prevent that:or: