Giovanni Bajo wrote on 02/07/2005 12:18:00:
>
> Yes, but the condition is still morally true in the code. NDEBUG is meant
to
> speed up the generated code, and it's actually a pity that instead it
> *disables* some optimizations because we don't see the condition anymore.
My
> suggestion is that assert with NDEBUG might expand to something like:
>
> if (condition)
>    unreachable();
>
> where unreachable is a function call marked with a special attribute
saying
> that execution can never get there. This way the run-time check is
> removed from
> the code, but the range information can still be propagated and used.
>
> Notice that such an attribute would be needed in the first place for
> gcc_unreachable() in our own sources. Right now we expand it to
gcc_assert(0),
> but we could do much better with a special attribute.

I always thought that when NDEBUG is set, then assert(x) should
have no side effects. So if "condition" contains any side effect,
or potential side effect (e.g. through function call), then the
compiler should not generate the code for "condition".

  Michael

Reply via email to