This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Infering that the condition of a for loop is initially true?

Joseph Myers <> writes:

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

>> 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);

Ouch, didn't think about that case. And I'd expect there's a lot of real
code like that out there.

That makes extending the standard assert facility more difficult.

Still, reusing the familiar name "assert" in the source code would be
nice, but the behavior I ask for would need to be triggered by something
other than -DNDEBUG, a gcc-specific define or command line option. And I
guess we can't hijack something like -DNDEBUG=2, even though I'd expect
that to be pretty close to working in practice.


Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]