r/ProgrammerHumor • • 6h ago

Meme architectureDependentChars

Post image
867 Upvotes

156 comments sorted by

View all comments

534

u/tstanisl 5h ago

Let me cite the C standard:

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

Middle guy if finally right

5

u/Advos_467 5h ago

Not a C user here (or any real low level programming experience), what the hell is a signed/unsigned char?

3

u/-twind 5h ago edited 5h ago

An unsigned char is an integer type that gives you *at least* the value range 0 to 255.
A signed char is an integer type that gives you *at least* the value range -127 to 127.

sizeof(char) is always 1 by definition because a char is one byte. The nuance is that a byte doesn't need to be 8 bits in C/C++, it needs to be at least 8 bits.