John Regehr on "Use of Assertions"

Timon Gehr timon.gehr at gmx.ch
Wed Sep 5 23:47:09 UTC 2018


On 01.09.2018 22:15, Walter Bright wrote:
> https://blog.regehr.org/archives/1091
> 
> As usual, John nails it in a particularly well-written essay.
> 
> "ASSERT(expr)
> Asserts that an expression is true. The expression may or may not be 
> evaluated.
> If the expression is true, execution continues normally.
> If the expression is false, what happens is undefined."
> 
> Note the "may or may not be evaluated." We've debated this here before. 
> I'm rather pleased that John agrees with me on this.

He does not! John gives two definitions. The first definition is the one 
I want, and he calls it _the best definition_. (I.e., all other 
definitions are inferior.)

> I.e. the optimizer 
> can assume the expression is true and use that information to generate 
> better code, even if the assert code generation is turned off.

The definition you quoted is the /alternative/ definition. He does not 
call it the best definition, and even explains that it can be dangerous. 
He says "it’s not an interpretation that is universally useful". (!)

I don't understand how you can conclude from this that John's view is 
that this should be the default -release behavior of assertions.


More information about the Digitalmars-d mailing list