<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 58</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="58"></A><H4>58.
  
Signedness of bit fields of enum type
</H4>
<B>Section: </B>11.4.10&#160; [<A href="https://wg21.link/class.bit">class.bit</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Steve Adamczyk
 &#160;&#160;&#160;

 <B>Date: </B>13 Oct 1998<BR>



<P>[Voted into WP at the October, 2006 meeting.]</P>

<P>Section 11.4.10 [<A href="https://wg21.link/class.bit">class.bit</A>]

paragraph 4 needs to be more specific about the signedness of bit
fields of enum type. How much leeway does an implementation have
in choosing the signedness of a bit field? In particular, does the
phrase "large enough to hold all the values of the enumeration" mean "the
implementation decides on the signedness, and then we see whether all the
values will fit in the bit field", or does it require the implementation
to make the bit field signed or unsigned if that's what it takes to make
it "large enough"?</P>

<P>(See also <A HREF="172.html">issue 172</A>.)</P>



<P>
<B>Note (March, 2005):</B> Clark Nelson observed that there is
variation among implementations on this point.  </P>

<P><B>Notes from April, 2005 meeting:</B></P>

<P>Although implementations enjoy a great deal of latitude in handling
bit-fields, it was deemed more user-friendly to ensure that the
example in paragraph 4 will work by requiring implementations to use
an unsigned underlying type if the enumeration type has no negative
values.  (If the implementation is allowed to choose a signed
representation for such bit-fields, the comparison against
<TT>TRUE</TT> will be <TT>false</TT>.)</P>

<P>In addition, it was observed that there is an apparent circularity
between 9.8.1 [<A href="https://wg21.link/dcl.enum#7">dcl.enum</A>] paragraph 7 and 11.4.10 [<A href="https://wg21.link/class.bit#4">class.bit</A>] paragraph 4 that should be resolved.
</P>

<P><B>Proposed resolution (April, 2006):</B></P>

<OL>

<LI>
<P>Replace 9.8.1 [<A href="https://wg21.link/dcl.enum#7">dcl.enum</A>] paragraph 7, deleting the
embedded footnote 85, with the following:</P>

<BLOCKQUOTE>

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.  It is possible to define an
enumeration that has values not defined by any of its enumerators.

</BLOCKQUOTE>
</LI>

<LI>
<P>Add the indicated text to the second sentence of
11.4.10 [<A href="https://wg21.link/class.bit#4">class.bit</A>] paragraph 4:</P>

<BLOCKQUOTE>

If the value of an enumerator is stored into a bit-field of the same
enumeration type and the number of bits in the bit-field is large
enough to hold all the values of that enumeration type
<INS>(9.8.1 [<A href="https://wg21.link/dcl.enum">dcl.enum</A>])</INS>, the original enumerator value and
the value of the bit-field shall compare equal.

</BLOCKQUOTE>

</LI>
</OL>

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