Reputation:
In the section N3797::3.9.1/2 [basic.fundamental]
there is:
There are five standard signed integer types : “
signed char
”, “short
int
”, “int
”, “long int
”, and “long long int
”. In this list, each type provides at least as much storage as those preceding it in the list.
The standard explicitly defines size of char, unsigned char, signed char
is 1. And that the size of plain int
s depends on INT_MIN
and INT_MAX
as far as I understand not-standartized. So is it possible for implementation to define INT_MIN
and INT_MAX
such that sizeof(int) = 1;
?
Upvotes: 1
Views: 254
Reputation: 16056
Yes. It is entirely possible for signed char
, short
, int
, long
, and long long
to all have the same 64-bit representation, which will have size 1.
The only effect this has on the standard library is to remove some typedefs from stdint.h
- specifically, int8_t
, int16_t
, int32_t
, int64_t
, uint8_t
, uint16_t
, uint32_t
, uint64_t
. Note that uint8_least_t
and uint8_fast_t
, etc., will still be provided.
Edit: add @user657267's link: 1 == sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long), which also includes the specific bit size requirements (though note that only the value ranges are normative)
The following value ranges must be supported:
signed char
: -(27-1) to 27-1unsigned char
: 0 to 28-1signed short
: -(215-1) to 215-1unsigned short
: 0 to 216-1signed int
: -(215-1) to 215-1unsigned int
: 0 to 216-1signed long
: -(231-1) to 231-1unsigned long
: 0 to 232-1signed long long
: -(263-1) to 263-1unsigned long long
: 0 to 264-1Edit: inlined more information from the links
Upvotes: 6
Reputation: 254461
Yes, as long as a byte has at least 16 bits, since that's the minimum size of int
.
This is common on DSP architectures, which typically only allow access to, for example, 32-bit words of memory, and no smaller units.
Upvotes: 4