Is there any reason why arithmetic operation on shorts and bytes return int?

d coder dlang.coder at gmail.com
Tue Dec 11 05:24:05 PST 2012


> No, it's a fix of a gotcha from C. The C code would just allow the
> assignment.


Yes Andrei.

But it does not look clean if you have to write:

byte a, b, c;
a = cast(byte) (b + c);

Well I know the advantages (safety). But imagine having to write all that
when working with bytes and shorts. Makes it really difficult to work with
shorts and bytes in D. Would I be asking for too much if I ask DMD to
provide a compiler flag that makes it return bytes and shorts for
operations on them? So the deal would be, if you use this compiler flag,
code behavior would be different from that of C/C++.

What we get would be more practical short and byte behavior.

Regards
- Puneet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20121211/9e4a5ee4/attachment.html>


More information about the Digitalmars-d mailing list