(Standard C99) What value will be contained in z.lines.line12 after assignment of -1 if sizeof(int) = 4?
union ZZZ {
    unsigned long long plain;
    struct {
        unsigned int line0:1;
        unsigned int line1:2;
        unsigned int line2:3;
        unsigned int line3:4;
        unsigned int line4:5;
        unsigned int line5:6;
        unsigned int line6:7;
        unsigned int line7:8;
        unsigned int line8:7;
        unsigned int line9:6;
        unsigned int line10:5;
        unsigned int line11:4;
        unsigned int line12:3;
        unsigned int line13:2;
        unsigned int line14:1;
    }lines;
};

void main() {
    ZZZ z;
    z.plain = (unsigned long long)-1;
}
Explanation
Bit fields that cross the type boundary will skip bits to align bits to the next type, for example, for an integer (unsigned int) cannot cross the 32-bit boundary. The line12 bit field will be located in the 9th byte from the beginning of z, i.e. it will not be initialized.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести