1

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 ints 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;?

2 Answers2

6

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-1
  • unsigned char: 0 to 28-1
  • signed short: -(215-1) to 215-1
  • unsigned short: 0 to 216-1
  • signed int: -(215-1) to 215-1
  • unsigned int: 0 to 216-1
  • signed long: -(231-1) to 231-1
  • unsigned long: 0 to 232-1
  • signed long long: -(263-1) to 263-1
  • unsigned long long: 0 to 264-1

Edit: inlined more information from the links

o11c
  • 15,265
  • 4
  • 50
  • 75
4

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.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
  • That's on DSP sizeof(signed char) = sizeof(short) = sizeof(int) and there are consumed 32 bits amount of storage. Right? –  Oct 09 '14 at 04:56
  • @DmitryFucintv: On a 32-bit architecture, with no addressable units smaller than 32 bits, yes. – Mike Seymour Oct 09 '14 at 04:57