Is there any reason why arithmetic operation on shorts and bytes return int?
Denis Koroskin
2korden at gmail.com
Tue Dec 11 19:37:54 PST 2012
On Wednesday, 12 December 2012 at 03:10:15 UTC, d coder wrote:
> On Wed, Dec 12, 2012 at 3:40 AM, Walter Bright
> <newshound2 at digitalmars.com>wrote:
>
>> No worries there :-) I feel pretty dang strongly about this
>> issue, from
>> bad experience.
>>
>> Even if a language behaves "wrong", it is still usable if it is
>> predictable.
>>
>
> Agreed.
>
> How about this.
>
> 1. Let "char" and "short" behave the C/C++ way. These can
> return integers.
> This will make C/C++ code work in D.
> 2. Make D "byte" operations return bytes. And create another
> type (named
> say dbyte or shortint) and make operations on the new type
> return
> shortints. This will make these types more usable in D code.
> Well we end up
> adding another keyword, but we shall get workable and safe
> 8-bit and 16-bit
> integrals.
>
> Regards
> - Puneet
What's now is safer than what you propose. You can always create
your own data type that would automatically truncate result if
you wish so.
More information about the Digitalmars-d
mailing list