Question about iteger literals
Uranuz via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jul 20 10:50:08 PDT 2014
On Monday, 23 June 2014 at 18:32:38 UTC, Steven Schveighoffer
wrote:
> On Sun, 22 Jun 2014 08:23:45 -0400, Uranuz <neuranuz at gmail.com>
> wrote:
>
>> If these rules are not so clear and have some exceptions (but
>> I don't understand why they are needed) then some
>> documentation needed about this.
>
> See integer promotion rules:
>
> http://dlang.org/type.html#Integer%20Promotions
>
> And the section below it.
>
> -Steve
I see these rules but when I compile following code and it fails
with error it looks VERY stupid.
import std.stdio;
void main()
{
ubyte a = 15;
ubyte b = 10;
ubyte c = a + b; //What is happening there?! AAAAARGH! Are you
joking?!
}
Compilation output:
/d837/f382.d(9): Error: cannot implicitly convert expression
(cast(int)a + cast(int)b) of type int to ubyte
I'm just crazy about it! How could it happen?!
More information about the Digitalmars-d-learn
mailing list