[Mesa-dev] [PATCH mesa 16/16] util: use NDEBUG to guard asserts

Gert Wollny gw.fossdev at gmail.com
Tue Nov 28 19:19:46 UTC 2017


Am Dienstag, den 28.11.2017, 10:53 +0000 schrieb Eric Engestrom:
> 
> > The parameters to a preprocessor macro are (basically) just
> > text.  They are not evaluated until after the macro is
> > expanded.  I'm 93.2% sure removing the guards around the assert()
> > should be fine in this case.
> 
> 100% sure :)
> look at /usr/include/assert.h:
> 
> #ifdef NDEBUG
> #define assert(expr) ((void) (0))
> #endif
> 
> The compiler doesn't even see the contents of `assert(foo)`, it's
> gone by the time the pre-compiler has done its job.


Unfortunately right now I had to learn the hard way that someone
decided to override the standard assert macro in

  gallium/auxiliary/util/u_debug.h 

so that now it expands to debug_assert, which in turn expands to 

   #define debug_assert(expr) (void)(0 && (expr))

if NDEBUG is defined, which means all of "expr" must be known to the
compiler. 

IMHO either the " && (expr)" part of that macro should be removed or
assert should not be redefined if NDEBUG is given. 

Best, 
Gert 




More information about the mesa-dev mailing list