should int/short/byte implicitly cast to dchar/wchar/char?

Walter Bright newshound2 at digitalmars.com
Mon May 16 21:33:24 PDT 2011


On 5/16/2011 9:09 PM, Jonathan M Davis wrote:
> On 2011-05-16 21:04, Don wrote:
>> It's not easy. Simply disallowing it would make code like this illegal:
>>
>> char c = '0' + n;
>
> Well, forcing the n to be cast to char or byte would do it, but that _is_ kind
> of ugly.
>
> char c = '0' + cast(char)n;
>
> Definitely a good point though.

It's THE reason why such casts are not allowed. Pascal requires such casts, and 
I always hated it for that.

The casts are not only annoying, they can cause bugs when the types of the rest 
of the expression are changed in maintenance.

There isn't any simple answer to mixed integer type arithmetic, although there 
are many "obvious" answers that have subtly pernicious behavior.



More information about the Digitalmars-d mailing list