Common type of ubyte and const ubyte is int
Walter Bright
newshound2 at digitalmars.com
Sat May 4 22:25:54 UTC 2024
On 5/3/2024 1:14 PM, matheus wrote:
> Like this D code:
>
> import std.stdio;
>
> void main(){
> char u;
> const char v;
> writefln("%d %d", (u.sizeof), (1?u:v).sizeof);
> }
>
> Prints: "1 1".
You're right.
But change `char` to `ubyte` and you'll get "1 4".
This is because the table in impcnvtab.d does not deal with char types:
https://github.com/dlang/dmd/blob/master/compiler/src/dmd/impcnvtab.d#L165
So, char types do not undergo integral promotion when trying to bring two
expressions to a common type. Byte, ubyte, short, and ushort do.
This can be debated as to which it should be, but there's a lot of water under
that bridge.
More information about the Digitalmars-d
mailing list