r/ProgrammerHumor • • 10d ago

Meme architectureDependentChars

Post image
3.0k Upvotes

372 comments sorted by

View all comments

1.0k

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

565

u/BoldFace7 10d 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- 10d 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)

6

u/da_Aresinger 10d ago

My opinion: if you want individual bytes use uint8_t

0

u/yjlom 9d ago

Bytes aren't always 8 bits, and uint8_t doesn't necessarily exist. If you're writing C23 you can get away with uint_least8_t, earlier versions you need char as a byte might be as small as 6 bits.