1 matches bool, 2 matches long

eles eles at eles.com
Mon Apr 29 07:34:48 PDT 2013


On Monday, 29 April 2013 at 14:08:20 UTC, Mike James wrote:
>> gdc:
>>
>> bool x = false;
>> x++;
>>
>> main.d:50: Error: operation not allowed on bool 'x'
>>
>> why not? is just an integer after all. another special case?
>
> If you are going to create a boolean then use it as a boolean - 
> it's not an integer any more. Don't mix and match - there's 
> nothing worse than trying to follow some code that uses a 
> variable in one way then, out of lazyness, uses it in a 
> different way.

that was exactly my point. that a boolean *should not* be an 
integer. and the case that I presented shows just another 
inconsistency of the relationship between booleans and integers 
in D. it works one way when it comes to function overloading, and 
another way when it comes to, let's say, ++ operator.



More information about the Digitalmars-d mailing list