regarding what seems (to me) unnecessary casts on integer expressions

Adam D. Ruppe destructionator at gmail.com
Sat Jun 5 02:07:03 UTC 2021


On Saturday, 5 June 2021 at 01:46:45 UTC, someone wrote:
> What's the point of declaring, for instance ushort's if then 
> nothing will treat them as ushort's and I have to manually 
> cast() everything to ushort() all the time ?

Yeah, it totally sucks.

D inherited a silly rule from C - the promote rules actually come 
from there - but then added a well-intentioned but pretty 
annoying in practice rule that discarding bits from arithmetic 
require an implicit cast. (Unless it is the bits over 32... then 
who cares. lol)

The += operator is exempt from it so use it where you can. But 
otherwise your only real hope is to do a user defined type with 
op overloads and what an enormous hassle.

This design was a mistake.


More information about the Digitalmars-d-learn mailing list