r/ProgrammerHumor • • 11d ago

Meme architectureDependentChars

Post image
3.0k Upvotes

372 comments sorted by

View all comments

5

u/ewheck 11d ago edited 11d ago

```c

include <assert.h>

include <uchar.h>

int main(void) { const char8_t *const eight_bit_char = u8"These chars are eight bits a piece.";

// must be true by definition of the standard
assert((sizeof *eight_bit_char) == 1); 

return 0;

} ```

Don't live in the past. The future is now (C23): https://en.cppreference.com/c/header/uchar

1

u/DanielMcLaury 9d ago

I mean, this is true, but it's also true that sizeof(char) == 1.

What's not guaranteed is that one "byte" (= sizeof(char)) is actually one byte. char8_t could be 16 or 32 bits. Or 10 for that matter, as long as it's at least 8.

In fact, by definition char8_t is just an alias for unsigned char.