Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

Switch Case Anomalies/Bugs

Open oldmanegan opened this issue 11 years ago • 3 comments

Guys, I searched and did not find this replicated elsewhere so here are my observations (for Arduino IDE 1.6.6:

  1. The switch case cannot be nested without causing issues.
  2. As well, it was found that if statements inside case statements may be unpredictable.
  3. As well, the for statement using ‘0’ as first entity value does not work, need to be ‘1’ based, then use decrement in the then statements to get to the zero element.
  4. Cannot define a variable inside a case statement.

oldmanegan avatar Nov 18 '15 18:11 oldmanegan

For points 1. 2. and 3. looks like bugs in your code than anomalies of the compiler, have you placed break after each case? http://www.drpaulcarter.com/cs/common-c-errors.php#2.1

  1. Cannot define a variable inside a case statement.

you can't, you must add instructions in curly braces { to do that }.

If the above doesn't solve your problem please post a sketch that shows the problem.

cmaglie avatar Nov 18 '15 18:11 cmaglie

Breaks are in each case statement. I will post code when I can get to it. If curly braces are required, then the Reference should state this explicitly. Please pass this on to the Reference people. Best Regards,

John [email protected]

On Nov 18, 2015, at 13:41 , Cristian Maglie [email protected] wrote:

For points 1. 2. and 3. looks like bugs in your code than anomalies of the compiler, have you placed break after each case? http://www.drpaulcarter.com/cs/common-c-errors.php#2.1 http://www.drpaulcarter.com/cs/common-c-errors.php#2.1 Cannot define a variable inside a case statement. you can't, you must add instructions in curly braces { to do that }. If the above doesn't solve your problem please post a sketch that shows the problem.

— Reply to this email directly or view it on GitHub https://github.com/arduino/Arduino/issues/4182#issuecomment-157814918.

oldmanegan avatar Nov 18 '15 18:11 oldmanegan

Reference updated to point this out.

agdl avatar Jul 12 '16 15:07 agdl