r/ProgrammerHumor 2d ago

Meme bugIntroducedDebugging

Post image
1.1k Upvotes

120 comments sorted by

View all comments

Show parent comments

41

u/ClipboardCopyPaste 2d ago

uint8_t

18

u/yjlom 2d ago

char would be the correct answer, as the C standard doesn't mandate a byte be 8 bits (6 and 32 are very uncommon nowadays but not unheard of, and there's a few machines out there that get really creative).

7

u/mckenzie_keith 2d ago

So even on weird platforms where char is a 32 bit type, sizeof (char) is 1, right? I can't remember.

2

u/AnnoyedVelociraptor 2d ago

FYI char in Rust is 32-bits, maximum size of a UTF-8 character

4

u/mckenzie_keith 2d ago

That is interesting. I know very little about rust.

2

u/cowslayer7890 2d ago

And in Java it's 16-bit, which means some Unicode characters get split in two

1

u/Xirdus 1d ago

Rust's char stores UTF-32, not UTF-8, but yes.

1

u/AnnoyedVelociraptor 1d ago

I did some more reading, and I wonder if it is more correct that Rust encodes Unicode Scalars as char?

1

u/Xirdus 1d ago

Technically speaking, the spec says char represents Unicode scalar, with actual encoding unspecified. The spec requires that char is 4 bytes and has the same ABI as u32, but that's it.

In practice, it's UTF-32.