www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - (u)byte calling char overload instead of int

reply puffi <no thank.you> writes:
Hi,
Is it by design that when calling functions with either ubyte or 
byte variables the char overload is called instead of the int (or 
generic) one?
Sep 01 2018
parent Peter Alexander <peter.alexander.au gmail.com> writes:
On Saturday, 1 September 2018 at 17:17:37 UTC, puffi wrote:
 Hi,
 Is it by design that when calling functions with either ubyte 
 or byte variables the char overload is called instead of the 
 int (or generic) one?
It seems this is by design. "If two or more functions have the same match level, then partial ordering is used to try to find the best match. Partial ordering finds the most specialized function." char is more specialized than int, and since the implicit conversion byte->char exists, it is called. Even f(1UL) will call f(char) rather than f(long).
Sep 01 2018