John Regehr on "Use of Assertions"

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Sep 5 16:24:58 UTC 2018


On Wed, Sep 05, 2018 at 03:59:06PM +0000, Michael via Digitalmars-d wrote:
> On Saturday, 1 September 2018 at 20:15:15 UTC, Walter Bright wrote:
> > 
> > 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. 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.
> 
> Is the part about the optimizer true in D's case? Or is this just a
> theoretical advantage to using asserts that are not evaluated in
> production code but left in?

AFAIK, no optimizer currently actually takes advantage of asserts in
this way.  But Walter has stated that this was his intention all along
when he made asserts a part of the language (as opposed to, e.g., a
macro / standard library call in C).

However, whenever he talks about this, there's always a big controversy
about potential pitfalls, and opinions are divided on this issue.


T

-- 
A linguistics professor was lecturing to his class one day. "In English," he said, "A double negative forms a positive. In some languages, though, such as Russian, a double negative is still a negative. However, there is no language wherein a double positive can form a negative." A voice from the back of the room piped up, "Yeah, yeah."


More information about the Digitalmars-d mailing list