MISRA Discussion Forums

Full Version: Rule 5-0-6 about underlying type of boolean bit field
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
}
This rule was not intended to apply to 1-bit bit-fields, which are always considered Boolean.

Your example should be compliant.