Title
Bits required for negative enumerator values
Status
cd5
Section
9.7.1 [dcl.enum]
Submitter
Hyman Rosen

Created on 2013-03-07.00:00:00 last changed 20 months ago

#### Messages

Date: 2018-06-15.00:00:00

Proposed resolution (June, 2018):

Change 9.7.1 [dcl.enum] paragraph 8 as follows:

bmax is the smallest value greater than or equal to max(|emin| - K, |emax|) , emax) and equal to 2M - 1, where M is a non-negative integer.
Date: 2018-11-15.00:00:00

[Accepted as a DR at the November, 2018 (San Diego) meeting.]

According to 9.7.1 [dcl.enum] paragraph 7,

For an enumeration whose underlying type is fixed, the values of the enumeration are the values of the underlying type. Otherwise, for an enumeration where emin is the smallest enumerator and emax is the largest, the values of the enumeration are the values in the range bmin to bmax, defined as follows: Let K be 1 for a two's complement representation and 0 for a one's complement or sign-magnitude representation. bmax is the smallest value greater than or equal to max(|emin|-K,|emax|) and equal to 2M-1, where M is a non-negative integer. bmin is zero if emin is non-negative and -(bmax+K) otherwise. The size of the smallest bit-field large enough to hold all the values of the enumeration type is max(M,1) if bmin is zero and M+1 otherwise.

The result of these calculations is that the number of bits required for

```  enum { N = -1, Z = 0 }
```

is 1, but the number required for

```  enum { N = -1 }
```

is 2. This is surprising. This could be fixed by changing |emax| to emax.

History
Date User Action Args