[Insight-developers] My Dashboard Compile Errors and assert()'s

Julien Finet julien.finet at kitware.com
Mon Aug 11 10:38:20 EDT 2008


On Mon, Aug 11, 2008 at 8:50 AM, Gaëtan Lehmann <gaetan.lehmann at jouy.inra.fr
> wrote:

>
>
> It would give something like that in the code:
>
>  itkAssertMacro( ptr != NULL, << "Input image can't be null." );
>  itkAssertMacro( v > 1, << "Distance must be greater than 1." );
>  itkAssertMacro( label != m_BackgroundValue, << "Foreground can't have the
> same label than background: " << label );
>
>
In my understanding of assertions, 2 of these cases are not exactly
assertions. A NULL input pointer is probably valid here, the filter wouldn't
do anything and give a NULL output then. Same for the distance < 1, a
distance equal to 0 is valid, it is meaningful. The filter won't do anything
but a distance equal to 0 is meaningful.

If you don't want to run an assertion that can be costly in Release mode,
then you can use a const expression (controlled by CMake?) to compile away
the assertion:
itkAssertMacro( NO_ASSERTS || check_tree(...), << "Input tree invalid" );

If your tree is invalid, maybe it should have been checked before (i.e. a
post-condition of the tree functions ).

Regards,
Julien.
p.s.: don't get me wrong, my email doesn't reply the assert() v.s. exception
question.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20080811/062e7b08/attachment.htm>


More information about the Insight-developers mailing list