Assert Expressions???
BCS
ao at pathlink.com
Thu Jul 26 15:12:15 PDT 2007
Reply to Gilles G.,
> 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
>>
in this case is shouldn't produce an error, however it shows that assert
is in fact an *expression* and not a statement as I would expect
this for instance, also works:
void main()
{
int i = 5 + (assert(false), 6);
}
while witting this it just occurred to me why assert should be an expression.
you can stuff it in logical expressions
while(ptr2ptr != null && (assert(*ptr2ptr != null), **ptr2ptr == 5)) {...}
More information about the Digitalmars-d-learn
mailing list