ushort calls byte overload

Oleg B via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 30 14:16:26 PDT 2017


Hello. I have this code

import std.stdio;

void foo(byte a) { writeln(typeof(a).stringof); }
void foo(short a) { writeln(typeof(a).stringof); }
void foo(int a) { writeln(typeof(a).stringof); }

void main()
{
     foo(0); // int, and byte if not define foo(int)
     foo(ushort(0)); // byte (unexpected for me)
     foo(cast(ushort)0); // byte (unexpected too)

     foo(cast(short)0); // short
     foo(short(0)); // short

     ushort x = 0;
     foo(x); // short
}

Is this a bug or I don't understand something?


More information about the Digitalmars-d-learn mailing list