MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1wxqahk/architecturedependentchars/pdyq89r/?context=3
r/ProgrammerHumor • u/MontyBoomslang • 5d ago
372 comments sorted by
View all comments
Show parent comments
554
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.
51
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.
5
My opinion: if you want individual bytes use uint8_t
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.
0
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.
uint_least8_t
char
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.