You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just spent a few hours trying to figure out what was wrong with my code as it was behaving very strangely (a for loop wouldn't increment) altough it was working just fine with the oficial core as well as with other microcontrollers.
I found I had defined a value returning function with several ifs and returns but the part the code was following didn't actually have a return in the end and therefore the pico was crashing. Here is a very simple example that replicates the issue in case my explanation isn't clear enough. Notice how printTest( ) doesn't return anything but is defined as an int returning function. I can see how a lot of people could get stuck with this issue as it isn't really easy to debug if the code is large.
int i;
void setup() {
Serial.begin(115200);
}
void loop() {
printTest();
delay(500);
}
int printTest(){
Serial.println(i);
i++;
}
Yeah it definitely isn't a mistake I usually do but this completely escaped me for a few hours until I finally realised what was going on😅
A patch would be awesome.
Activity
earlephilhower commentedon Jul 4, 2021
Good catch. That is a programming error and according to the C spec is "undefined behavior" so crashing is acceptable there.
I was going to port in the following patch from the ESP8266, but completely forgot. Thanks for reminding me!
esp8266/Arduino#8165
RandomHacks-Git commentedon Jul 4, 2021
Yeah it definitely isn't a mistake I usually do but this completely escaped me for a few hours until I finally realised what was going on😅
A patch would be awesome.
Add warning flags to build, catch missing return
earlephilhower commentedon Jul 4, 2021
Not only did I need to add the patch, it turns out I had forgot to add any of the warning options to the actual compile options. D'oh!
No matter what the warning options, your sample will fail to build with the following report using the PR:
Add warning flags to build, catch missing return (#237)
pio: allow programs with 32 instructions (earlephilhower#236)