I want a debug function-macro that works like this:
int myVar = 5;
PRINTVAR(myVar); // macro
// which expands to something like...
print("myVar: ");
println(myVar);
Basically, I want to use the identifier as a string literal as well as a variable.
I'm just getting a bit sick of repeating myself when I want to dump out a whole lot of variables to the stdout.
My silly attempt, which of course doesn't work:
#define PRINT_VAR(x) Serial.print("x: "); Serial.println(x);
Is this possible?
do { Serial.print("x: "); Serial.println(x); } while (0)idiom if you must use semicolons. Note that at least one answer carefully avoids semicolons by using a comma operator instead.