Is there any reason why arithmetic operation on shorts and bytes return int?
bearophile
bearophileHUGS at lycos.com
Tue Dec 11 06:31:36 PST 2012
d coder:
> 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;
I think this dis-uniformity was added because:
- Statistically it's more common to have an overflow when you sum
two bytes compared to summing two ints.
- If the sum of two ints/uints requires a cast, you need to fill
your code with casts. And casts are not safe at all, they are
sharp powertools.
(I have asked many times for runtime integral overflows in D (as
in C#/Delphi), that can be disabled with a compilation switch.
But D designers come from the great unsafety of C-like languages
and do not agree with me on the dangers/bugs of fixnum
operations).
Bye,
bearophile
More information about the Digitalmars-d
mailing list