cesp8266

suggest parentheses around arithmetic in operand of '|' [-Werror=parentheses] ESP8266 spi


The VScode complains about the last &dout_data

WRITE_PERI_REG(SPI_W0(spi_no),((0xFFFFFFFF<<(dout_bits-dout_extra_bits)&dout_data)<<(8-dout_extra_bits)|
                                            (0xFFFFFFFF>>(32-(dout_bits-dout_extra_bits)))&dout_data));
                                                                                          ^

and command&

WRITE_PERI_REG (SPI_USER2 (spi_no),((((cmd_bits-1)&SPI_USR_COMMAND_BITLEN)<<SPI_USR_COMMAND_BITLEN_S)|
                                            command&SPI_USR_COMMAND_VALUE));
                                            ^

Strange to see as these warnings i didnt see when i was compiling with older version SDK


Solution

  • The VScode complains about the last &dout_data) … and command&

    The compiler message “suggest parentheses around arithmetic in operand of '|'” means the compiler is suggesting you put parentheses around the subexpression it is pointing to with the ^. That would be around (0xFFFFFFFF>>(32-(dout_bits-dout_extra_bits)))&dout_data in the first case and around command&SPI_USR_COMMAND_VALUE in the second case.

    Strange to see as these warnings i didnt see when i was compiling with older version SDK

    New software often brings new features, including new warnings or new detections of things to warn about.