On Sun, 9 Nov 2014, Sandra Loosemore wrote:

> Hrmmm.  In C, sp->a has type "3-bit unsigned integer" which is promoted to int
> by the integral promotions since all values are representable as int.   sp->c
> has type "5-bit unsigned integer" which is likewise promoted to int.  In C++,
> sp->a has type "unsigned char" and sp->c has type "unsigned long long".  By
> the C++ conversion rules, "unsigned char" is promoted to int (again since all
> values are representable), and "unsigned long long" is not promoted to
> anything else.

But C++ does still promote the unsigned long long:5 bit-field to int (4.5 
[conv.prom]#5, in C++11: "A prvalue for an integral bit-field (9.6) can be 
converted to a prvalue of type int if int can represent all the values of 
the bit-field; otherwise, it can be converted to unsigned int if unsigned 
int can represent all the values of the bit-field. If the bit-field is 
larger yet, no integral promotion applies to it. If the bit-field has an 
enumerated type, it is treated as any other value of that type for 
promotion purposes.").

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to