Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By walt22
#32536 Hello,

after the migration to Chert´s SDK 1.3, I got the following warning message from the compiler:

Suggested parenthesis around expression 'PIN_FUNC_SELECT(LED_GN_MUX, LED_GN_FUNC)' user_main.c ...

Because it has worked in SDK 0.95, I am confused. Looking into the makro, defined in eagle_soc.h, I tried to put some additional paranthesises around some expressions, but without any success.
If somebody has a solution, please let me know.

Many thanks and best regards
Walter
User avatar
By amadeus84
#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.
User avatar
By walt22
#32630 Hello Amadeus,
Many thanks for your quick and helpful replay.
I have tested now two versions, the original and the one with your modification. Both versions worked correctly, but in both versions, I got the warning message.
May be, I have to live with the warnings, but I hate all of them.

Best regards
Walter
User avatar
By amadeus84
#32676 Oh, if your code compiles with the warnings, then you're ok. My makefile had -Werror in CFLAGS and it didn't compile without either fixing the warning, or removing the flag.

It's strange that you're still getting the warning after you use parentheses as in my previous post. I don't.