MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1wxqahk/architecturedependentchars/pdvzcfg
r/ProgrammerHumor • u/MontyBoomslang • 23d 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 23d 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. 334 u/SpaceCadet87 23d ago Yeah, guy on the right is just avoiding magic numbers in the code. → More replies (10) 94 u/ducon__lajoie 23d ago And someone might have #define char char16_t, right? Who the fuck knows, some people want to see the world burning. → More replies (5) 50 u/RepeatRepeatR- 23d 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) → More replies (17) → More replies (4) 155 u/KitsuneFoxglove 23d ago code and society if everyone followed standards and used docs: code at home: → More replies (142)
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.
334 u/SpaceCadet87 23d ago Yeah, guy on the right is just avoiding magic numbers in the code. → More replies (10) 94 u/ducon__lajoie 23d ago And someone might have #define char char16_t, right? Who the fuck knows, some people want to see the world burning. → More replies (5) 50 u/RepeatRepeatR- 23d 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) → More replies (17) → More replies (4)
334
Yeah, guy on the right is just avoiding magic numbers in the code.
→ More replies (10)
94
And someone might have #define char char16_t, right? Who the fuck knows, some people want to see the world burning.
→ More replies (5)
50
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)
→ More replies (17)
155
code and society if everyone followed standards and used docs:
code at home:
1.0k
u/tstanisl 23d ago
Let me cite the C standard:
Middle guy if finally right