Common type of ubyte and const ubyte is int
Daniel N
no at public.email
Thu May 2 18:09:56 UTC 2024
On Thursday, 2 May 2024 at 17:25:55 UTC, user1234 wrote:
> On Thursday, 2 May 2024 at 16:25:15 UTC, DrDread wrote:
>> I'm for not having types promote at all. it's been an endless
>> source of bugs for me. it messes with metaprogramming.
>
> 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
}
```
More information about the Digitalmars-d
mailing list