Topic: (m ? t.i : t.j) = 1; for bit-fields ??


Author: olsen@verdix.com (David Olsen)
Date: 23 Jul 93 18:35:01 GMT
Raw View
Is the following program legal?

----------
struct s {
    unsigned int i : 5;
    unsigned int j : 6;
    unsigned int k : 6;
};

int main()
{
    int m = 1;
    struct s t;

    (m ? t.i : t.j) = 1; // A
    (m ? t.j : t.k) = 1; // B
    (m ? t.k : t.k) = 1; // C

    return 0;
}
----------

My reading of the ARM is that it is legal.  Section 9.6 says "A
bit-field must have integral type," indicating that a bit-field is one
of the standard integral types and does not have its own type.
Section 5.16 says "The result [of the conditional operator] is an
lvalue if the second and the third operands are of the same type and
both are lvalues."

Therefore, line C is definitely legal because t.k obviously has the
same type as itself.  It is line A that bugs me.  t.i and t.j are
different sizes, but they are both of type unsigned int, so the line
appears to be legal.

Has the C++ committee decided anything that contradicts the ARM on
these points?

--
David Olsen
olsen@verdix.com