I'm running the following Sketch on my Arduino Uno:
const boolean verbose = true;
void debug(const char *s){
if(verbose){
char buf[8 + sizeof(s)] = "[DEBUG] ";
strcat(buf, s);
Serial.println(buf);
}
}
void setup() {
Serial.begin(115200);
char str[] = "Lorem ipsum dolor sit amet, consetetur sad";
Serial.print("Size of String: ");
Serial.println(sizeof(str));
debug(str);
}
void loop() {
}
The debug()
function should be used to print debugging information to Serial. The Sketch like I posted it works wuite fine and prints the following to Serial:
Size of String: 43
[DEBUG] Lorem ipsum dolor sit amet, consetetur sad
But when I add one more character to the string (43 chars excluding null terminator) I get the only follwoing on Serial:
Size
This problem does not appaer when defining str
as a global varaible. What does cause this issue and how can it be fixed?