Why am I getting the compiler error below?
1 2 3 4 5 6 7 8 9 10 11
|
typedef uint8_t byte;
setBit(char *ch, int bitnum, bool set)
{
uint8_t mask = 1 << bitnum;
if ( set ) (byte)*ch |= mask; // <--- lvalue required as left operand.
else (byte)*ch &= ~mask;
}
|
Last edited on
Expression (byte)*ch is rvalue. You may not assign a value to it. You can write simply
*ch |= mask;
or
*ch = (byte) *ch | mask;
I originally had
*ch |= mask;
and the compiler complained about an invalid type conversion, unsigned int to char.
I changed the function argument from char to byte to eliminate the error.