Can't add ubytes together to make a ubyte... bug or feature?
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jan 19 15:36:14 PST 2016
On Tuesday, 19 January 2016 at 22:12:06 UTC, Soviet Friend wrote:
> I don't care if my computer needs to do math on a 4 byte basis,
> I'm not writing assembly.
x86 actually doesn't need to do math that way, if you were
writing assembly, it would just work. This is just an annoying
rule brought over by C.
> Can I prevent the initial implicit casts?
Nope, though you can help tell the compiler that you want it to
fit there by doing stuff like
ubyte a = 200;
ubyte b = 100;
ubyte c = (a+b)&0xff;
or something like that, so the expression is specifically proven
to fit in the byte with compile time facts.
More information about the Digitalmars-d-learn
mailing list