From c4a08f1e1ed029aca81a158dc11fe37f01e0843a Mon Sep 17 00:00:00 2001 From: Paul Melnikov Date: Sun, 22 Aug 2021 23:04:57 +0700 Subject: [PATCH] Fix `bitWrite` with parenthesis Current version does not wrap arguments in "()", so works incorrectly when used like this: ``` bitWrite(var, bit, cond?1:0); ``` Same as in here: https://github.com/espressif/arduino-esp32/issues/4466 --- cores/arduino/wiring_constants.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/arduino/wiring_constants.h b/cores/arduino/wiring_constants.h index 054f708162..cb8760fa64 100644 --- a/cores/arduino/wiring_constants.h +++ b/cores/arduino/wiring_constants.h @@ -91,7 +91,7 @@ enum BitOrder { #define bitRead(value, bit) (((value) >> (bit)) & 0x01) #define bitSet(value, bit) ((value) |= (1UL << (bit))) #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) -#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) +#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet((value), (bit)) : bitClear((value), (bit) )) #define bit(b) (1UL << (b)) //macro added for compatibility