G'day folks,
I'd just like to share a bug that kept me stumped for about three hours. Contemplate the following code:
class BadClass
{
public:
BadClass();
};
BadClass::BadClass()
{
delay(100);
}
// This will call the BadClass constructor.
BadClass aBadObject;
void setup()
{
// This will never get called.
pinMode(13, OUTPUT);
}
void loop()
{
// This will never get called.
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
This sketch will happily compile and be uploaded. An instance of aBadObject is allocated memory on the stack, and the BadClass() default constructor is called. The constructor then calls "delay()" - before setup() is called. I don't know what happens on the microcontroller at this point, but nothing in the setup() or loop() gets called. You can't blink an LED or write anything to the serial monitor.
Fascinating!