Common type of ubyte and const ubyte is int

matheus matheus at gmail.com
Fri May 3 20:14:18 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.

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".

=]

Matheus.


More information about the Digitalmars-d mailing list