Hi,
I've just updated my IDE to version 1.8.9 and I believe I've found a bug in the compilation of switch/case/default statements.
A variable is both declared and initialised within a case statement (see test code attached)
- the case statements up to the one in question (included), work fine;
- the case/default statements that follow the one in question, they DO NOT WORK.
Even though the compiler doesn't complain, some of the libraries I've developed in the past started to behave oddly because of that
There is a workaround solution, but...
#include <Arduino.h>
void setup() {
Serial.begin(115200);
while (!Serial);
switch (2) {
case 0:
break;
case 1:
// case 2 doesn't work
byte c = 1;
/*
// case 2 works
byte c;
c = 1;
*/
break;
case 2:
Serial.println(F("Ciao!"));
break;
}
Serial.println(F("That's all folks!"));
}
void loop() {
}
Testing environment: IDE 1.8.9 on MAC + Arduino Mega 2560
Ciao,
Iacopo.