Assert Expressions???

Bill Baxter dnewsgroup at billbaxter.com
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);
>>> }
>>> 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

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.

--bb


More information about the Digitalmars-d-learn mailing list