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.

Reply via email to