minimal evaluation
Daniel Keep
daniel.keep.lists at gmail.com
Mon Apr 6 04:49:33 PDT 2009
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
I can't find anything in the language spec that mandates it, but I do
believe the compiler supports boolean short-circuiting (that's what I've
always seen it called.) There was a bug report a long time ago that
this didn't happen for CTFE, and it was fixed as a bug, so I assume
short-circuiting is the intended behaviour.
Perhaps this should go in the spec; it's certainly something I expect
from any half-sane language.
-- Daniel
More information about the Digitalmars-d
mailing list