Menu

Is this a bug in the Arduino IDE?

#arduino#redditarduino#ifdef#endif#serial
Reading 0:00
15s threshold

I am using the Arduuino IDE 2.3.7 to compile, upload, and debug code for an orignal ESP32 .

I came across a weird behavior where a for-loop did not work. I boiled it down to a simple sketch. It includes a function that returns true or false. If the path does not include a return statement, the code does not work right. Sketch is below. The loop does not do anything. The last line of the test function is the key. If I comment out the return statement, the for-loop does not work right and it doesn't exit until n = 18. The compiler does not catch this.

Is this a bug to report?

``` void setup() { // put your setup code here, to run once: Serial.begin(9600); delay(1000); if (test(6)) Serial.println("true"); else Serial.println("false"); } bool test(int N) { Serial.println("Testing... "); for (int n = 0; n < N; n++) { if (n >= 18) return true; else Serial.println(n); delay(200); } // if this line is commented, n reaches 18.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.