3 ms·
> often 1 byte char is always 1-byte according to the C standard. (Actually, I think it's more like the smallest addressable unit is 1-char, but it's been I wh
by messe 6y ago
> often 1 byte
char is always 1-byte according to the C standard. (Actually, I think it's more like the smallest addressable unit is 1-char, but it's been I while since I've read the spec)
- vlovich123 6y agoIt is now. There were more esoteric platforms for which it was defined as 2 bytes (eg csr8675 and the Kalimba DSP coprocessor was even 24-bit char, short and ints). Until recently C only defined that char was the smallest unit and had size 1. I think as of C11 that may have changed. It definitely did in C++ because basically any platform that mattered defined char as 1 byte and any platforms that didn’t also didn’t really care about portability of existing software that much as the porting is generally more involved anyway (eg I ported a crypto library to Kalimba and it was challenging to get the bit math correct but eventually I did).
- messe 6y ago> and the Kalimba DSP coprocessor was even 24-bit char, short and ints Yes, but sizeof char would still be 1, unless I'm mistaken. I think I might have made a major pedagogical mistake when I declared char == 1 byte. What I meant was that when you're working in C, a char is the smallest addressable unit. Now, that smallest addressable unit is conventionally known as a byte, but it might not be 8-bits wide. These days it is almost always is thankfully. Thank you for clarifying that, because I don't think my original comment was clear enough. I've been meaning for a while to write a blog post on the origins of 8-bit bytes as well as other conventions in CS.
- gens 6y agoEDIT: I was wrong, a char is always sizeof 1, See https://news.ycombinator.com/item?id=26131228 https://news.ycombinator.com/item?id=26131228 // old reply: I already replied to nanis above, so i+l just c/p it here. CHAR_BIT is a minimum of 1 byte (8 bits), but is not guaranteed to be 1. http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf (Annex E)
- uhhhhhhhhhhhhhh 6y agoWhat if there were hardware with a smallest adressable size of N bits, but its next size up were a noninteger multiple of N?