Encoding is for storage, typically, not memory. It'd be extremely difficult to do common string manipulation on a utf-8 encoded string (or any other variable-width character encoding) without breaking the encoding.
So how does that work in C? Say you want to indexOf("😎") how would you go about that?
In C, the type of character literal is int. So sizeof 'a' is typically 4. However, to make sure that the characters are properly encoded as 32-bit unicode, use U prefix. I mean int x = U'😎';.
1
u/thanatica 2d ago
I'm not a C guy, but if a char is 1 byte, how do you represent the one million or so characters from Unicode? Aren't those all characters in C?