Assert Expressions???

Bill Baxter dnewsgroup at
Thu Jul 26 16:48:15 PDT 2007

BCS wrote:
> 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);
>>> }
> 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

It looks like a function call and smells like a function call, so why 
shouldn't it act like a function call?  Calling a function is an 
expression, so why shouldn't assert() be an expression too?  Seems 
perfectly reasonable to me.  Expressions can also be used in more places 
than statements, as you point out, so if it makes sense as an expression 
then might as well allow it to be used that way.


More information about the Digitalmars-d-learn mailing list