Is there a standards-complaint method to represent a byte in ANSI (C89/90) C? I know that, most often, a char happens to be a byte, but my understanding is that this is not guaranteed to be the case. Also, there is stdint.h in the C99 standard, but what was used before C99?
I’m curious about both 8 bits specifically, and a ‘byte’ (sizeof(x) == 1).
charis always a byte , but it’s not always an octet. A byte is the smallest addressable unit of memory (in most definitions), an octet is 8-bit unit of memory.That is,
sizeof(char)is always 1 for all implementations, butCHAR_BITmacro inlimits.hdefines the size of a byte for a platform and it is not always 8 bit. There are platforms with 16-bit and 32-bit bytes, hencecharwill take up more bits, but it is still a byte. Since required range forcharis at least -127 to 127 (or 0 to 255), it will be at least 8 bit on all platforms.Emphasis mine.