Code crashing in a struct #1111
Unanswered
CreativeRobotics
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I don't know why, but gcc can't handle variable initialisation inside the switch case. If you want to initialize a Variable inside a case, you'll need to do that insida a scope, aka curly braces. Is there any initialisation in the swich case? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
EDIT - Damn it, I meant Switch, not Struct ...
I can't tell if this is an issue with code, a compiler optimisation bug or something else so I thought I would ask here.
I've been trying to use the Microchip DALI1 control gear stack on Arduino with MegaTinyCore (DALI is a lighting control system for commercial buildings). I downloaded it as a demo project using AtmelSTART and then extracted all the stack files, and put them in an src folder in a sketch. I renamed all the .c files to .cpp, and added an include Ardhino.h to the file called DALI_top.h and them rearranged the code that would have been in main, to be in the sketch.
It compiles - yipee!
When I run it on an attiny1616 it will crash shortly after starting. I traced the crash to a case statement in the function that handles fading.
I can't see anything wrong with the code that would cause it to crash here so I tried removing the entire switch statement and replacing it with a series of if else conditions and now the code compiles and runs, I can send it commands from a DALI controller and it will respond correctly.
If I recompile it for an attiny3217 the code will crash. I can't work out where ...
What I can't get my head around is why it is crashing when I use a device that just has extra pins and memory, or why the switch statement was causing a crash on the first device - its Microchips official software stack and it reportedly works fine so I don't understand why it goes wrong when I compile with megaTinyCore, particuarly why its failing in a switch statement.
I was hoping some more technically skilled programmers might point me to where the problem could be:
Is it a compiler optimisation issue?
Is it because I did something naughty trying to get the c code to work with c++?
Is it something else I failed to understand entirely?
Beta Was this translation helpful? Give feedback.
All reactions