If I want my program to be able to run in debug mode, is it a good idea to make it accept a flag such as -D=DEBUG
when I run the program? I currently have a DEBUG
variable in a .h
file but that I can't change after I compile.
#define DEBUG false
I'd like to be able to run my program both in debug mode and "stable" mode. Is getops a good option for doing this since I already use getops for accepting the args ./a.out --help
and ./a.out --version
?
#define
and#ifdef
you actually change which parts of your code are compiled and make it to the final binary. People typically use this approach so that debug code doesn't make it to a production release (even if they are 99% sure it won't be invoked). Leaving debug code in a production build is just a liability. Also, I'm pretty sure you miss out on tons of compiler optimisations when you release in debug mode.