Boost logo

Boost :

Subject: Re: [boost] suggestion on assertion macros
From: Roland Bock (rbock_at_[hidden])
Date: 2010-03-15 14:28:16


DE wrote:
[snip]
>> I plan on using that myself. I think it would be useful for others, too.
>>
> i came to the same thing
> this solution works perfect with msvc80 and i feel like going to
> adopt it for my personal use
>
> but i think you missed the order of macro directives
> if i get it right it should be
>
> #ifdef NDEBUG
> #ifdef assert
> #undef assert
> #endif //swapped this and the following lines
> #define assert(cond) static_cast<void>(sizeof(cond? 0: 0));
> #endif
>
> and i agree that defining an "advanced" project-specific macro is
> really a better solution than redefinition of 'assert()'
>
Right, so I end up with

#include <cassert>

#ifndef NDEBUG
   #define my_assert(cond) assert(cond)
#else
   #define assert(cond) static_cast<void>(sizeof(cond? 0: 0));
#endif

I think I'll advocate this thing every once in a while :-)

Today I stumbled across a warning in Spirit 2.1 (did not look at the
current code) which could have been removed by using such an assert
definition.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk