Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 5-0-6 about underlying type of boolean bit field
#1
Quote:Rule 5–0–6 (Required) An implicit integral or floating-point conversion shall not reduce the size of the underlying type.

Refer to the Bit-field operands part of determination of the underlying type of an expression
Quote:Bit-field objects have an underlying type equivalent to an integral type of a size determined by their width. For example, a bit-field with width n, will have the same underlying type as a fundamental type with the same sign and width (if one exists).

However, for one bit field, there's no any fundamental type with only one bit.
So what exactly are bitAs' and bitBs' underlying types? Please help to clarify, thanks.

Code:
struct
{
    bool bitA : 1;
    int  bitB : 1;
} boolbitfield;

int main()
{
    bool b = boolbitfield.bitA; // compliant or non-compliant?
}
Reply
#2
This rule was not intended to apply to 1-bit bit-fields, which are always considered Boolean.

Your example should be compliant.
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)