Why does this not work?

Shachar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Sep 17 06:20:13 PDT 2014


On Wednesday, 17 September 2014 at 13:03:05 UTC, flamencofantasy 
wrote:
> the result of ubyte + ubyte is int I believe.
>
> Try;
> void func( int c )
> {
>      ubyte a;
>
>      a = cast(ubyte)(cast(ubyte)c + cast(ubyte)c);
> }

 From http://dlang.org/type, under Usual Arithmetic Conversions:
4. Else the integer promotions are done on each operand, followed 
by:
     1. If both are the same type, no more conversions are done.

So, as far as I can see, the specs disagree with you.

Shachar


More information about the Digitalmars-d-learn mailing list