Common type of ubyte and const ubyte is int
user1234
user1234 at 12.de
Thu May 2 18:34:03 UTC 2024
On Thursday, 2 May 2024 at 18:09:56 UTC, Daniel N wrote:
> On Thursday, 2 May 2024 at 17:25:55 UTC, user1234 wrote:
>> On Thursday, 2 May 2024 at 16:25:15 UTC, DrDread wrote:
>>> [...]
>>
>> PLs that dont promote have their own problems too. The most
>> obvious is that overflowing is more easy. At least promotion
>> mitigates that.
>>
>> However I'm quite sure that D promotions rules were not seen
>> as such. It's more C compatibility, walking on the C tracks,
>> to speak metaphorically.
>
> C++ actually gets it right(!)
>
> ```d
> #include <cstdint>
> #include <cstddef>
> #include <cstdio>
>
> int main(void)
> {
> uint8_t a = {};
> const uint8_t b = {};
> const uint16_t c = {};
>
> auto x = 1 ? a : b;
> auto y = 1 ? a : c;
>
> fprintf(stderr, "### %zu\n", sizeof(x)); // 1
> fprintf(stderr, "### %zu\n", sizeof(y)); // 4
> }
> ```
I see, c++ promotes, but differently. D specs should be revised.
Probably the rules mentioned earlier, those from ANdrei, should
be sorted differently.
More information about the Digitalmars-d
mailing list