mardi 30 octobre 2018

C++ Union/Struct Bitfield Implementation and Portability

I have a union containing a uint16 and a struct like so:

union pData {
    uint16_t w1;
    struct {
        uint8_t d1 : 8;
        uint8_t d2 : 4;
        bool b1 : 1;
        bool b2 : 1;
        bool b3 : 1;
        bool b4 : 1;
    } bits;
};

My colleague says there is an issue with this being portable, but I am not sure I buy this. Could some please explain (simple as possible) what is "wrong" here?

Aucun commentaire:

Enregistrer un commentaire