fix build errors with -DNDEBUG

Paul Eggert eggert@cs.ucla.edu
Mon Jul 27 06:25:00 GMT 2015


Martin Sebor wrote:
> When glibc is compiled with -NDEBUG the
> macros expand to nothing and, without the attribute or some
> similar annotation, GCC complains about the variables being
> unused.

That's a common problem with assert and NDEBUG.  We solve this problem in a 
different way in the Emacs source code, with something like this:

#ifdef ENABLE_CHECKING
# define eassert(cond) ((cond) ? (void) 0 : die (#cond, __FILE__, __LINE__))
#else
# define eassert(cond) ((void) (0 && (cond)))
#endif

That way, GCC doesn't complain when assertions are disabled, because the 
variables are "used" even when !ENABLE_CHECKING.  Perhaps glibc could use a 
similar idea in a private macro after 2.22 is released.   (Obviously standard 
'assert' can't work this way.)



More information about the Libc-alpha mailing list