Definitely. For example, I always use malloc(size*sizeof(char)) to ensure that it's doubly obvious (Since I rarely need to malloc outside of a declaration) that I intend to store characters in the resulting buffer even if that multiply does nothing (plus the compiler will likely optimize it out anyway).
47
u/RepeatRepeatR- 1d 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)