2022-05-24 09:54 PM
Hello. I would like to print certain messages to UART only in DEBUG mode. These prints will not be necessary in release mode.
I have tried the following:
#ifdef DEBUG
printf("hello from debug \n");
#endif
And then I have built the project for both release and debug but the message is printed in both cases. How can I only get message to print in debug mode and not in release mode?
Solved! Go to Solution.
2022-05-25 06:52 AM
@Piranha "#ifdef is, of course, the most appropriate here"
Not in this case, where DEBUG is always being defined - as either 0 or 1.
In which case I would still prefer something of the form:
#if DEBUG == 0
// whatever
#elif DEBUG == 1
// whatever else
#else
#error "DEBUG must be either 0 or 1"
#endif
so that there's no ambiguity or unexpected surprises if a value other than 0 or 1 gets used.
I did already note that it's more conventional to only define DEBUG when needed, and test with #ifdef - but OP seems to prefer having it always defined, and checking the value.
2022-05-25 07:47 AM
Yes - for "Debug" configuration, not "Release" as seen on your screen.