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: Re: assert caveat
From: Benjamin Franksen <[email protected]>
To: [email protected]
Date: Sat, 11 Oct 2008 19:32:15 +0200
On Samstag, 11. Oktober 2008, Till Straumann wrote:
> 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 standard solution is to use a variable name that sufficiently describes 
the asserted invariant. For instance

#define epicsMutexMustLock(ID) {\
  epicsMutexLockResultIsOk_ ## ID =\
    (epicsMutexLock((ID))==epicsMutexLockOK);\
  assert(epicsMutexLockResultIsOk_ ## ID); }

Cheers
Ben

References:
assert caveat Till Straumann

Navigate by Date:
Prev: LvEPICS on USB Key pre-release Mauro Giacchini
Next: Building CAP5 under windows or cygwin David Morris
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: assert caveat Till Straumann
Next: Re: assert caveat Andrew Johnson
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 ·