Jun 14, 2013 at 9:50pm
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 Jun 14, 2013 at 10:08pm
Jun 14, 2013 at 11:46pm
Expression (byte)*ch is rvalue. You may not assign a value to it. You can write simply
*ch |= mask;
or
*ch = (byte) *ch | mask;
Jun 17, 2013 at 4:03pm
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.