-2

my basic aim, as heading suggests, is to get debug code removed in release code, when expending before compilation. For now, I am using _Debug(or custom name) macro to guard debug line which works just fine.

But, I don't want to write the per-processor guard for every function / operation call like writing in a C++ debug file.

Edit: Thanks for response, If I can create macro function that guards itself while expending like : DBG_PRINT(fname,msg)\ #ifdef _Debug\ fprintf(fname, msg)\ #endif.

Please suggest me some clean and single liner way-out.

Thanks and Happy coding

Pervez Alam
  • 1,246
  • 10
  • 20

1 Answers1

1

Pre processor instruction is the only way to do it, you can clean the code and avoid ifdef Debug put everywhere in the code if you wrap the debug calls in a common method that has the body ifdefined, but there isn't a way to do it without Macro or preprocessor checks.

user1709665
  • 142
  • 7
  • _"if you wrap the debug calls in a common method that has the body ifdefined"_ The function will still be linked (probably optimized out when having an empty body though). – πάντα ῥεῖ Jun 04 '15 at 13:46
  • @πάντα ῥεῖ sure but the code is more readable and safe if wrapped in a method than having macros, especially if you have a very large project. In fact a Compile error in a Macro it's a pain in the ass. – user1709665 Jun 04 '15 at 13:50
  • Problem is, that such functions probably need to return a value for chaining (e.g. with an overloaded `operator<<()`,). Thus you can't completely leave them with an empty body. – πάντα ῥεῖ Jun 04 '15 at 13:58
  • @πάνταῥεῖ not necessarily if you create a "Log" method which get a string format and parameters you can create it without returning anything but usable enough to create complex Logging strings. – user1709665 Jun 04 '15 at 14:06