I have a system in which I specify the level of detail on the command line. In my functions, I check what has been indicated to determine if I am entering the code for the code or not:
#ifdef DEBUG if (verbose_get_bit(verbose_level_1)) { // arbitrary debugging/printing style code generally goes in here, eg: printf("I am printing this because it was specified and I am compiling debug build\n"); }
I would like to make this less tedious to configure, so here is what I still have:
// from "Verbose.h" bool verbose_get_bit(verbose_group_name name); // verbose_group_name is an enum
Now I can do it:
IF_VERBOSE_BIT_D(verbose_GL_debug) { printf("I don't want the release build to execute any of this code"); glBegin(GL_LINES);
I like it because it looks like an if-statement, it functions like an if-statement, it clearly indicates that it is a macro, and it does not run in the release build.
I would be sure that the code would be optimized, since it would be wrapped in an if(false) block, but I would prefer some way to force the preprocessor to actually throw away the whole block. It can be done?
source share