<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1636</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="1636"></A><H4>1636.
  
Bits required for negative enumerator values
</H4>
<B>Section: </B>9.8.1&#160; [<A href="https://wg21.link/dcl.enum">dcl.enum</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD5
 &#160;&#160;&#160;

 <B>Submitter: </B>Hyman Rosen
 &#160;&#160;&#160;

 <B>Date: </B>2013-03-07<BR>


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

<P>According to 9.8.1 [<A href="https://wg21.link/dcl.enum#7">dcl.enum</A>] paragraph 7,</P>

<BLOCKQUOTE>

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 <I>e<SUB>min</SUB></I> is the smallest
enumerator and <I>e<SUB>max</SUB></I> is the largest, the values of
the enumeration are the values in the range <I>b<SUB>min</SUB></I> to
<I>b<SUB>max</SUB></I>, defined as follows: Let <I>K</I> be 1 for a
two's complement representation and 0 for a one's complement or
sign-magnitude representation.  <I>b<SUB>max</SUB></I> is the smallest
value greater than or equal to
max(|<I>e<SUB>min</SUB></I>|-<I>K</I>,|<I>e<SUB>max</SUB></I>|) and
equal to 2<I><SUP>M</SUP></I>-1, where <I>M</I> is a non-negative
integer.  <I>b<SUB>min</SUB></I> is zero if <I>e<SUB>min</SUB></I> is
non-negative and -(<I>b<SUB>max</SUB></I>+<I>K</I>) otherwise.  The
size of the smallest bit-field large enough to hold all the values of
the enumeration type is max(<I>M</I>,1) if <I>b<SUB>min</SUB></I> is
zero and <I>M</I>+1 otherwise.

</BLOCKQUOTE>

<P>The result of these calculations is that the number of bits
required for</P>

<PRE>
  enum { N = -1, Z = 0 }
</PRE>

<P>is 1, but the number required for</P>

<PRE>
  enum { N = -1 }
</PRE>

<P>is 2.  This is surprising.  This could be fixed by changing
|<I>e<SUB>max</SUB></I>| to <I>e<SUB>max</SUB></I>.</P>

<P><B>Proposed resolution (June, 2018):</B></P>

<P>Change 9.8.1 [<A href="https://wg21.link/dcl.enum#8">dcl.enum</A>] paragraph 8 as follows:</P>

<BLOCKQUOTE>

<I>b</I><SUB>max</SUB> is the smallest value greater than or
equal to <I>max</I>(|<I>e</I><SUB>min</SUB>| - <I>K</I><DEL>,
|<I>e</I><SUB>max</SUB>|)</DEL>
<INS>, <I>e</I><SUB>max</SUB>)</INS> and equal to
2<SUP><I>M</I></SUP> - 1, where <I>M</I> is a non-negative
integer.

</BLOCKQUOTE>

<BR><BR>
</BODY>
</HTML>
