Thread overview |
---|
April 06, 2009 minimal evaluation | ||||
---|---|---|---|---|
| ||||
Hi All, Is minimal evaluation always enabled in D? I want to write a function IsNull(), so that I can check the precondition as follows: if (isNull(foo) || isNull(foo.getBar) || isNull(foo.getBar.getBar2) { return false; } // normal code goes here If an argument is null, the IsNull() will return false. Internally it will be logged to console as well. But I am not sure, if dmd-compiler generates code without minimal evaluation in some cases. If minimal evaluation is not always enabled. I cannot do precodition check in my way. --Qian |
April 06, 2009 Re: minimal evaluation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Qian Xu | >
> if (isNull(foo) ||
> isNull(foo.getBar) ||
> isNull(foo.getBar.getBar2)
> {
> return false;
> }
Update: If minimal evaluation is not always enabled, and foo.getBar is NULL. I will get a segfault when evaluating foo.getBar.getBar2.
|
April 06, 2009 Re: minimal evaluation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Qian Xu | On 06.04.2009 13:30, Qian Xu wrote:
> Hi All,
>
> Is minimal evaluation always enabled in D?
>
> I want to write a function IsNull(), so that I can check the precondition as
> follows:
>
> if (isNull(foo) ||
> isNull(foo.getBar) ||
> isNull(foo.getBar.getBar2)
> {
> return false;
> }
> // normal code goes here
>
> If an argument is null, the IsNull() will return false. Internally it will
> be logged to console as well.
>
> But I am not sure, if dmd-compiler generates code without minimal evaluation
> in some cases. If minimal evaluation is not always enabled. I cannot do
> precodition check in my way.
>
> --Qian
If you mean short-circuit evalutation, I'm pretty sure that's always what the compiler does.
|
April 06, 2009 Re: minimal evaluation | ||||
---|---|---|---|---|
| ||||
Posted in reply to torhu | torhu wrote: > > If you mean short-circuit evalutation, I'm pretty sure that's always what the compiler does. Thanks. Somebody posted this link: http://digitalmars.com/d/1.0/expression.html#OrOrExpression |
Copyright © 1999-2021 by the D Language Foundation