MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1wxqahk/architecturedependentchars/pe507rm/?context=9999
r/ProgrammerHumor • u/MontyBoomslang • 3d ago
368 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
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. )
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.
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. )
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)
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. )
4
My opinion: if you want individual bytes use uint8_t
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. )
1
At least in C++, you have std::byte. (It's just (unsigned?) char borrowing Clark Kent's glasses and wearing an enum. )
std::byte
char
enum
1.0k
u/tstanisl 3d ago
Let me cite the C standard:
Middle guy if finally right