J-M0 / dbg.h

Quick and dirty print debugging
Mozilla Public License 2.0
29 stars 0 forks source link

Rely on standard NDEBUG to remove debug statements in production? #1

Open aartaka opened 4 months ago

aartaka commented 4 months ago

Hi! I've seen your library on r/C_programming, and I noticed a similarity of your macros and built-in assert macro. One notable feature of this macro is that it expands to a null value when NDEBUG macro is defined. Which is handy if you want to disable costly asserts in production.

Maybe use the same mechanism to disable debugging statements when NDEBUG is defined? That'd be a good solution for the

They probably shouldn't hang around in your code for a long time outside of tests and the like.

part of the README—if you can disable debug macros, they are safer to use in whatever scenario there is.

J-M0 commented 3 months ago

Hi there! I actually did have this feature in an earlier version, but I deliberately removed it. In keeping with the spirit of dbg!, I wanted my macros to behave more or less the same in release builds as they do in debug builds, so I actually don't want them controlled by NDEBUG.

aartaka commented 3 months ago

The name (dbg) implies use in debug builds and complex debugging scenarios. Which is likely not the same as release. In case you want consistent behavior between debug and release, you use a logging, not debugging.