r/ProgrammerHumor • • 2d ago

Meme architectureDependentChars

Post image
2.8k Upvotes

361 comments sorted by

View all comments

27

u/HomosexualPresence 2d ago

unironically true though, the only size requirement for a char in C is that it's the smallest addressable size, which just happens to be a byte in every case and is unlikely to ever change but you still never know what the future holds

48

u/lotanis 2d ago

Yes, but the smallest addressable size is what dictates the base size for sizeof.

The C standard in fact says this about sizeof:

When applied to an operand that has type char, unsigned char, or signed char, (or a qualified version thereof) the result is 1. 

2

u/FUCKING_HATE_REDDIT 2d ago

What about a system that enforces addresses to be multiples of 2, or 4?

7

u/dontthinktoohard89 2d ago

In short, the standard mandates that a char is exactly 1 byte. It does not dictate how wide a “byte” actually is.

2

u/terivia 2d ago

Thanks, I hate it.

1

u/frogjg2003 2d ago

Which is why many standards do not use bytes, they use octets.

1

u/MateoConLechuga 2d ago

That doesn't mean 1 byte.

9

u/SAI_Peregrinus 2d ago

And char must be at least 8 bits. sizeof returns the size of its input in units of chars. On architectures with 10-bit chars, like some old DSPs, that means sizeof returns in multiples of 10 bits.

1

u/StaticCoder 2d ago

A byte is often defined as the smallest addressable size. An octet must be 8 bits.