I’d like to make a debug logging function with the same parameters as printf. But one that can be removed by the pre-processor during optimized builds.
For example:
Debug_Print('Warning: value %d > 3!\n', value);
I’ve looked at variadic macros but those aren’t available on all platforms. gcc supports them, msvc does not.
I still do it the old way, by defining a macro (XTRACE, below) which correlates to either a no-op or a function call with a variable argument list. Internally, call vsnprintf so you can keep the printf syntax:
Then a typical #ifdef switch:
Well that can be cleaned up quite a bit but it’s the basic idea.