This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: fix build errors with -DNDEBUG
- From: Paul Eggert <eggert at cs dot ucla dot edu>
- To: Martin Sebor <msebor at gmail dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Sun, 26 Jul 2015 23:25:25 -0700
- Subject: Re: fix build errors with -DNDEBUG
- Authentication-results: sourceware.org; auth=none
- References: <55A83361 dot 6010506 at gmail dot com> <20150717020539 dot GF5641 at vapier> <87pp3r9lco dot fsf at igel dot home> <20150720072047 dot GO5641 at vapier> <55ACF099 dot 4050301 at redhat dot com> <55ADBEEE dot 6030401 at gmail dot com> <alpine dot DEB dot 2 dot 10 dot 1507221717340 dot 21570 at digraph dot polyomino dot org dot uk> <55AFD628 dot 2020000 at gmail dot com> <55B28F9A dot 8010802 at redhat dot com> <55B56DDB dot 4010307 at gmail dot com>
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.)