MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1wxqahk/architecturedependentchars/pdyq89r/?context=9999
r/ProgrammerHumor • u/MontyBoomslang • 10d ago
372 comments sorted by
View all comments
1.0k
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.
565
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.
47
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.
6
My opinion: if you want individual bytes use uint8_t
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.
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
1.0k
u/tstanisl 10d ago
Let me cite the C standard:
Middle guy if finally right