fork download
//main.c
//Why does y get set to 0 in the case of 'Breaks'?
//Compile with gcc -fms-extensions main.c

#include 

struct Base {
    int x;
    int y;
};

struct Extend {
    union {
        int X;
        struct Base bb;
    } uu;
};

struct AlsoExtend {
    struct Base bb;
    int z;
};

static struct Extend Works = {
    .uu.bb.x = 5,
    .uu.bb.y = 3,
    //.X = 2
};

static struct Extend Breaks = {
    .uu.bb.x = 5,
    .uu.bb.y = 3,
    .uu.X = 2
};

static struct AlsoExtend AlsoWorks = {
    .bb.x = 5,
    .bb.y = 3,
    .z = 69
};

int main(int argc, char** argv) {

    printf("Works: x:%d y:%d X:%d\n", Works.uu.bb.x, Works.uu.bb.y, Works.uu.X);
    printf("Breaks: x:%d y:%d X:%d\n", Breaks.uu.bb.x, Breaks.uu.bb.y, Breaks.uu.X);
    printf("AlsoWorks: x:%d y:%d z:%d\n", AlsoWorks.bb.x, AlsoWorks.bb.y, AlsoWorks.z);

    return 0;
}
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
Works: x:5 y:3 X:5
Breaks: x:2 y:0 X:2
AlsoWorks: x:5 y:3 z:69