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

d coder dlang.coder at gmail.com
Tue Dec 11 06:01:58 PST 2012


On Tue, Dec 11, 2012 at 7:05 PM, Peter Alexander <
peter.alexander.au at gmail.com> wrote:

> That's the whole point. What you are doing is dangerous, so it requires
> the cast.
>


What I am doing is not dangerous. I am operating at byte/short level.
Tell me, if what I am doing is dangerous, how come doing the following is
not dangerous. It is allowed by D.

int a, b, c;
a = b + c;

Also the sense of safety that you get for short and byte too is not
complete. Consider:

void main() {
  import std.stdio;
  ushort a = ushort.max;
  ushort b = ushort.max;
  a += b;
  writeln(a);
}


Is it too much to ask for consistent behavior across the built-in types?

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


More information about the Digitalmars-d mailing list