Assert Expressions???
Robert Fraser
fraserofthenight at gmail.com
Thu Jul 26 15:13:06 PDT 2007
Of course it won't produce any error. It's a conditional expression, so if X and Y are expressions, a ? X : Y will evaluate to X if a is true, and Y if a is false.
In this expression, this means that if a is true, the expression evaluates to assert(a), which is assert(true), which is always true. If a is false (as in the case with this code, because boolean values default to false when first initialized), the conditional will evaluate to assert(!a), which is assert(!false), which is also obviously true. a ? assert(a) : assert(!a); will _always_ evaluate to true.
Gilles G. Wrote:
> I tried this code and... it won't produce any error. I still don't understand why. Could you please report the (odd) explaination?
>
> --
> Gilles
> BCS Wrote:
>
> > this is just odd
> >
> > void main()
> > {
> > bool a;
> > a ? assert(a) : assert(!a);
> > }
>
> >
> > http://www.digitalmars.com/d/expression.html
> >
> >
>
More information about the Digitalmars-d-learn
mailing list