EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: assert caveat
From: Till Straumann <[email protected]>
To: EPICS Techtalk <[email protected]>
Date: Fri, 10 Oct 2008 15:09:08 -0700
Unless I miss something then it seems to me
that EPICS uses 'assert()' in the same way I often
do which AFAIK is incorrect:

assert( expression_with_side_effect );

because if the code is ever compiled with -DNDEBUG then
the side effect (eg locking a mutex in epicsMutexMustLock())
*goes*away*.

'assert' is a macro which evaluates to nothing if NDEBUG is defined.

The correct way of using assert would be:

result = expression_with_side_effect;

assert(result);

but it is inconvenient because the message printed by a failed
assertion would only say 'assertion of 'result' failed' and it would
not print the stringified expression.

My guess is that a lot of code would break if ever compiled
with -DNDEBUG...

Again:

#define NDEBUG
epicsMutexMustLock(my_lock);

is a no-op!

FWIW
-- Till


PS: It would be rather useful to have something like


#ifdef NDEBUG
#define usefulEpicsAssert(exp) (exp)
#else
#define usefulEpicsAssert(exp) ((exp) ? (void)(0) : assert(exp))
#endif

Replies:
Re: assert caveat Benjamin Franksen
Re: assert caveat Andrew Johnson

Navigate by Date:
Prev: Base R3.14.10-RC2 Released Andrew Johnson
Next: Re: Base R3.14.10-RC2 Released Till Straumann
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: Base R3.14.10-RC2 Released Till Straumann
Next: Re: assert caveat Benjamin Franksen
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 02 Sep 2010 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·