5 ms·
5 bytes? What about 5 characters? When I started almost four decades ago it was then true that bytes and characters were the same thing.
by DannyB2 6y ago
5 bytes? What about 5 characters?
When I started almost four decades ago it was then true that bytes and characters were the same thing.
- aYsY4dDQ2NrcNzA 6y agoI don’t think that was guaranteed, at least not in C. Wasn’t that implementation-dependent?
- MereInterest 6y agoSort of, yeah. In C, the size of the integer primitives isn't defined. What is defined is that sizeof(char) will always be 1 (one). However, it is entirely implementation defined what that 1 refers to. On most systems, it is the number of 8-bit bytes, but it could refer to a larger or smaller amount of memory.
- wahern 6y ago> but it could refer to a larger or smaller amount of memory. Never smaller as the minimum limits for char require at least 8 bits. But definitely can be wider than 8 bits, as is common on DSPs or some old mainframes. Though, even on systems that don't permit direct addressing of 8-bit char, C implementations will sometimes emulate it. FWIW, POSIX mandates a fixed, 8-bit char.
- bnegreve 6y ago> However, it is entirely implementation defined what that 1 refers to. Not entirely, there is a vague description of what a byte should be able to represent. The C and C++ programming languages define byte as an "addressable unit of data storage large enough to hold any member of the basic character set of the execution environment" https://en.wikipedia.org/wiki/Byte https://en.wikipedia.org/wiki/Byte
- lambda_obrien 6y agoThat's no longer true, in case you were wondering. People still say `bytes <-"instead of"-> chars` sometimes but we should stop that.