<Limits.h>
Do you have a reference? I've always seen a byte defined as 8 bits. No matter what. (Unless you're talking to a hard drive manufacturer, that's a different bucket of worms though.)
"3.5 bit
unit of data storage in the execution environment large enough to hold an object that may have one of two values
NOTE It need not be possible to express the address of each individual bit of an object.
3.6 byte
addressable unit of data storage large enough to hold any member of the basic character set of the execution environment
NOTE 1 It is possible to express the address of each individual byte of an object uniquely.
NOTE 2 A byte is composed of a contiguous sequence of bits, the number of which is implementation-defined. The least significant bit is called the low-order bit; the most significant bit is called the high-order bit."
I can't find any indication that a byte is the minimum addressable unit. I guess that is because of 4-bit CPUs and/or CPUs that can address individual bits.
It also uses "byte" very sparingly, most of the time in the context of multibyte (not hyphenated) to single-byte (hyphenated) conversions, but also in section 5.2.1:
"The representation of each member of the source and execution basic character sets shall fit in a byte."
And there also is a guarantee that a unsigned char is as large as a byte in a footnote to section 6.2.6.1:
"A byte contains CHAR_BIT bits, and the values of type unsigned char range from 0 to 2^CHAR_BIT − 1"
I doubt that char and unsinged char can be of different size, but didn't check that.
For C, see C11 §3.6: “byte — addressable unit of data storage large enough to hold any member of the basic character set of the execution environment” http://www.iso-9899.info/n1570.html#3.6
§ 6.5.3.4 The sizeof operator
[…]
Semantics
2 The sizeof operator yields the size (in bytes) of its operand,
[…]
3 When applied to an operand that has type char, unsigned char, or signed char, (or a qualified version thereof) the result is 1.
What I'd like to know is, how common are non-8-bit-byte CPUs these days, for new devices?
I worked with Texas Instruments C54x and C55x DSPs back in the early 2000s (https://en.wikipedia.org/wiki/Texas_Instruments_TMS320#C5000...). They had 16-bit chars and that was incredibly annoying -- very few low-level third-party libraries would even compile properly. Are those still used?
It seems like everything has an ARM chip on the side these days, so maybe (hopefully) there's less need to run application code on bizarre DSPs. Except for those unsung heroes maintaining old set-top boxes and the like.
- sizeof returns size in bytes;
- sizeof (char) == 1;
- one byte has CHAR_BIT bits;
- CHAR_BIT >= 8.
Can you link a reference to this? Seems backwards/weird.
In the programming languages C and C++, the unary operator sizeof generates the size of a variable or datatype, measured in the number of char size storage units required for the type. As such, the construct sizeof (char) is guaranteed to be 1.