float init 0 request
Walter Bright
newshound2 at digitalmars.com
Fri Aug 21 23:04:20 UTC 2026
On 8/20/2026 2:46 PM, Steven Schveighoffer wrote:
> Given the first statement's behavior, you would expect `dchar` type
> to mean *re-encode*, as this is what it is doing (this is a special
> compiler-generated decoding feature).
The compiler generated decoding feature would be:
```d
foreach (dchar d; "Über");
```
The `"Über".byCodeUnit` is not recognized as special by the compiler, other than
being a range. It does not cause foreach to re-encode.
"Über".byCodeUnit` returns a type that is a code unit matching the encoding of
its argument, in this case a UTF-8 string, so a `char` is returned. `char` is
implicitly convertible to `dchar`.
> But any char element type other than char arrays int promotes.
It promotes to the type of foreach's first argument type, in this case, dchar.
> Subtle changes in meaning for the same syntax are bug factories.
Yes, but the syntax is different:
```d
foreach (dchar d; "Über")
foreach(dchar d; "Über".byCodeUnit) // <=== different!
foreach(dchar d; "Über".byDchar) // the droid you are looking for
```
> This is why I really like `~` being the concat operator instead of `+`.
I really like it, too!
> If integer promotion to dchar didn't work, then you would know immediately what
> the problem is.
char promotes to dchar.
More information about the Digitalmars-d
mailing list