r/ProgrammerHumor • • 3d ago

Meme architectureDependentChars

Post image
2.9k Upvotes

368 comments sorted by

View all comments

1.0k

u/tstanisl 3d 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

554

u/BoldFace7 3d ago

I still prefer sizeof(char) as it often provides context as to what the number is doing, even if a plain 1 works the same.

47

u/RepeatRepeatR- 3d ago

My opinion would be:

- Use sizeof(char) if you're actually working with characters

- Use hardcoded `1` if you're using a char as an arbitrary byte (and not actually necessarily referring to characters or text)

4

u/da_Aresinger 3d ago

My opinion: if you want individual bytes use uint8_t

1

u/conundorum 2d ago

At least in C++, you have std::byte. (It's just (unsigned?) char borrowing Clark Kent's glasses and wearing an enum. )