Common type of ubyte and const ubyte is int

Daniel N no at public.email
Sat May 4 15:34:48 UTC 2024


On Friday, 3 May 2024 at 19:40:36 UTC, Walter Bright wrote:
> On 5/1/2024 7:42 AM, Steven Schveighoffer wrote:
>> It seems rule 2 would apply instead of rule 6? but I don't 
>> like it.
>
> ```
> #include <stdio.h>
>
> void main()
> {
>     char u;
>     const char v;
>     printf("%ld %ld\n", sizeof(u), sizeof(1?u:v));
> }
> ```
>
> This prints "1 4". D follows the same integral promotion rules, 
> and the reason is if one translates C code to D, one doesn't 
> get an unpleasant hidden surprise.

However as you can see in my post
https://forum.dlang.org/post/fhmzjloxfzzwgmohkxnc@forum.dlang.org
C++ actually went the other direction on this, in the rare cases 
that they differ, shouldn't D be free to chose the best option 
from C or C++?

Considering C++ had auto ever since C++11 but it was only 
recently added in C23. There's a lot more C++ code that depends 
on the type than C code.




More information about the Digitalmars-d mailing list