3 ms·
Let DEBUG be a compile time constant, and the optimizer will remove the check. What do you feel is gained with "const int DEBUG" over "#define DEBUG"? While mo
by nkurz 11y ago
Let DEBUG be a compile time constant, and the optimizer will remove the check.
What do you feel is gained with "const int DEBUG" over "#define DEBUG"? While most compilers will do what you say most of the time, I haven't encountered a significant downside to the macro approach.
I also like that I can have a makefile where "make debug" adds "-DDEBUG" to the compiler command line and appends "_debug" to the executable name. With the const approach, is there an easy way to automatically generate both debug and production executables?
- majewsky 11y agoI guess the argument is orthogonality. It is a desirable property in programming languages to not have overlapping features, because people will always be confused about when to use which (the classic example being pointers vs. references in C++).
- gpderetta 11y agoOne advantage is that the protected code will be syntax and typechecked even if it is "compiled" out. That will make it less likely to bitrot.
- thealistra 11y agoYeah it's hard to keep exponentially many code configurations that may compile together. It's hard to support in an IDE. Where a variable works nicely