We need to define terms more precisely. sizeof(char) will always be 1. But on some platforms, char is not an 8-bit type. It could actually be a 32 bit type. The c programming language does not (I believe) acknowledge or define what a byte is. But if it is an 8 bit integer type, then char will not always be one byte.
It may be better to say "octet" instead of "byte" in this type of discussion.
The implementation has to define CHAR_BIT in <limits.h>. CHAR_BIT is the number of bits in variables of type "char".
It's kinda funny that C99 introduced int8_t and made it optional, but I'm sure there's some good reason. Basically if that type exists, then CHAR_BIT is 8. Also POSIX.1-2001 defines it that way, so most people can safely assume it.
8
u/meat-eating-orchid 2d ago
technically, an int could even be just one byte if you are on an architecture where a byte (= smallest addressable unit) has 16 bit