assert, NDEBUG and you

Chris Robinson chris.kcat at gmail.com
Mon Oct 26 18:33:17 CDT 2015


On 10/26/2015 03:31 PM, Michael Stefaniuc wrote:
> I'm too the opinion that code with too many assert()s sprinkled in is
> unfinished code and shouldn't go in as is.  Of course it can go into
> Staging that way. But even in that case you want a plain  assert() and
> not a wrapper that is disabled for users., User feedback is an important
> part of the development process.

The asserts are used for development, and are no longer needed for a 
proper release. The problem comes with something like Wine where you 
have a large code base with developers that come and go over time. So 
one developer finishes what they're doing and no longer needs the 
asserts, but someone else comes along later to work on the code and 
could use those asserts (but wouldn't know to put them in).

I've also found asserts to be useful for static analysis. Where you know 
something will be true because other code has already made sure of it, 
but analysis of the function reports a problem. The assert clears away 
that false-positive, but checking it at runtime is wasteful and 
unnecessary, especially for release builds.

> And last but not least, IMHO, crashing is the far better response than
> silently corrupting user data. So yes, using -NDEBUG is misguided.

Not all uses of debug checks are necessary for release builds (IMHO, if 
you need most/all of your debug checks in a release build, perhaps it's 
not ready for release). In such cases there's no danger of corrupt data 
or crashing, but during future development there may be. Using -DNDEBUG 
is no more misguided than not using -D_DEBUG. In both cases, you're 
saying you don't need those debugging features.

FWIW, I've also desired a variant of assert() that doesn't get compiled 
out in release builds, since assert() does by default, but that doesn't 
mean I want all assert()s to stay in release. Having variants of assert 
where one stays and another goes away for release would be useful. It's 
a shame some distros have taken it upon themselves to determine whether 
NDEBUG is used or not, since now developers like me can't know how a 
standard function like assert() will behave in release.



More information about the wine-devel mailing list