- Thu Oct 29, 2015 10:01 am
#32552
If you write
A & B | C
then A & B is done first, then the | because the bitwise & has precedence over the bitwise or |.
So without parentheses, the code should be fine. To be sure you really want A & B | C and not
A & (B | C) the compiler prefers (A & B) | C, i.e. it wants parentheses around the bitwise &.
So there are two ways to go about this:
1) Ignore the warning. Some 3-rd party code (like esp8266-wireless-switcher) has -Werror in the compiler flags, which will make the compilation fail if it encounters any warnings. I see this in just about any C code I come across, perhaps because everyone is mechanically using some primordial Makefile. Just remove the -Werror token from the CFLAGS variable in the Makefile.
2) Put parentheses in the right places in eagle_soc.h like so:
Code: Select all#define PIN_FUNC_SELECT(PIN_NAME, FUNC) do { \
WRITE_PERI_REG(PIN_NAME, \
(READ_PERI_REG(PIN_NAME) \
& (~(PERIPHS_IO_MUX_FUNC<<PERIPHS_IO_MUX_FUNC_S))) \
| ( (((FUNC&BIT2)<<2)|(FUNC&0x3))<<PERIPHS_IO_MUX_FUNC_S) ); \
} while (0)
Now this is where the compiler wants parentheses: around the operands of the bitwise &.
But I have no idea if that's where they need to be. I mean, I don't know if the author really meant (A & B) | C or A & (B | C).
After lots of tinkering I just managed last night to compile esp8266-wireless-switcher, with the parentheses as above. I'm about to flash it on the chip, so I'll know for sure then.