Reputation: 528
I read this sentence, while reading the "C++ Primer Book". What exactly does this sentence mean? And what are examples of those various kinds of hardware? How were the arithmetic types designed to do that? (at least consideration that were made to achieve that). Thanks in advance.
Upvotes: 3
Views: 87
Reputation: 27577
Care is taken in the C++ standard not to restrict arithmetic types in such a way as to make them "unnatural" to any given hardware. Most implementations, for example, use 2's complement integers and use IEEE Standard 754 for floating point numbers. But they don't have to in order to be compliant with the standards. They could be 1's complement integers and not use IEEE Standard 754 for floating point types if that suited the hardware better and still be fully compliant with the C++ standard.
Upvotes: 3
Reputation: 76438
In C and C++ a char
has to be at least 8 bits wide. A short
has to be at least 16 bits wide and at least as wide as a char
. An int
has to be at least 16 bits wide and at least as wide as a short
. A long
has to be at least 32 bits wide and at least as wide as an int
. A long long
has to be at least 64 bits wide and at least as wide as a long
.
Note all those "at least"s. Each of those types can be wider than the minimum that's allowed, and when one of those types is wider it ripples through the rest of the types.
There are DSP chips out in the wild today that only address 32-bit values, so char
is 32 bits wide, short
is 32 bits wide, and int
is 32 bits wide. That's an example of catering to the peculiarities of that hardware.
Upvotes: 2