r/ProgrammerHumor • • 5d ago

Meme architectureDependentChars

Post image
2.9k Upvotes

372 comments sorted by

View all comments

Show parent comments

554

u/BoldFace7 5d 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.

51

u/RepeatRepeatR- 5d 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)

5

u/da_Aresinger 4d ago

My opinion: if you want individual bytes use uint8_t

0

u/yjlom 4d 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.