On Mon, 18 Sep 2017, Niels Möller wrote:

> Andreas Schwab <sch...@suse.de> writes:
> 
> > The problem is that assert is not allowed to evaluate the expression
> > with -DNDEBUG, and side effects must not be carried out.
> 
> I'm suggesting that with -DNDEBUG, assert(x) should let the compiler
> assume that x is true, but without producing any code to evaluate it at
> runtime.

There's no requirement that x is even a valid expression with -DNDEBUG.  
Consider code that does

  int x;
#ifndef NDEBUG
  int other_variable_used_in_assertion = something ();
#endif
  /* ... */
  assert (other_variable_used_in_assertion == x);

where it is completely valid in ISO C not to have the NDEBUG conditional 
around the assert call, because in the NDEBUG case the macro argument 
won't be expanded.

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to