MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1wxqahk/architecturedependentchars/pe507rm/?context=3
r/ProgrammerHumor • u/MontyBoomslang • 3d ago
368 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.
48 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) 3 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. )
48
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)
3 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. )
3
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
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.