我无法弄清楚为什么会这样。我正在使用一堆非常复杂的结构、联合、两者的未命名版本、静态变量等......但我确信这应该有效。经过一天的调试,我将问题缩小到以下代码中发生的情况。我正在使用-fms-extensions,它似乎不能很好地适应这种情况:
//main.c
//Why does y get set to 0 in the case of 'Breaks'?
//Compile with gcc -fms-extensions main.c
#include <stdio.h>
struct Base {
int x;
int y;
};
struct Extend {
union {
int X;
struct Base;
};
};
struct AlsoExtend {
struct Base;
int z;
};
static struct Extend Works = {
.x = 5,
.y = 3,
//.X = 2
};
static struct Extend Breaks = {
.x = 5,
.y = 3,
.X = 2
};
static struct AlsoExtend AlsoWorks = {
.x = 5,
.y = 3,
.z = 69
};
int main(int argc, char** argv) {
printf("Works: x:%d y:%d X:%d\n", Works.x, Works.y, Works.X);
printf("Breaks: x:%d y:%d X:%d\n", Breaks.x, Breaks.y, Breaks.X);
printf("AlsoWorks: x:%d y:%d z:%d\n", AlsoWorks.x, AlsoWorks.y, AlsoWorks.z);
return 0;
}