Why can't D store all UTF-8 code units in char type? (not really understanding explanation)

Adam D Ruppe destructionator at gmail.com
Fri Dec 2 21:24:21 UTC 2022


On Friday, 2 December 2022 at 21:18:44 UTC, thebluepandabear 
wrote:
> It's his explanation as to why this code doesn't compile even 
> though Ğ is a UTF-8 code unit:

That's not a utf-8 code unit.

A utf-8 code unit is just a single byte with a particular 
interpretation.

> If I do `char.sizeof` it's 2 bytes

Are you sure about that? `char.sizeof` is 1. A char is just a 
single byte.

The Ğ code point (note code units and code points are two 
different things, a code point is an abstract idea, like a 
number, and a code unit is one byte that, when combined, can 
create the number).


More information about the Digitalmars-d-learn mailing list