I have been experiencing some problems with a code I am writing. After some work I were able to reduce the code to the following MWE:
class Problem {
public:
Problem(char * problematic_chars) {
delay(1); // If this line is commented there is no problem.
}
};
Problem its_a_hard_life("abc");
void setup() {
Serial.begin(9600);
}
void loop() {
int i = 0;
while (true) {
Serial.println(i++);
delay(500);
}
}
If I upload that, exactly as it is, to my Arduino Uno, it hangs and nothing is shown in the serial monitor. If the line with the comment is commented, everything works as expected. Also, if the Problem constructor does not receive anything, things work fine. I mean that the following code works OK:
class Problem {
public:
Problem(void) {
delay(1);
}
};
Problem its_a_hard_life();
void setup() {
Serial.begin(9600);
}
void loop() {
int i = 0;
while (true) {
Serial.println(i++);
delay(500);
}
}
What is wrong with the first code?