检查下面的代码片段
struct st
{
struct st
{
int a ;
int b ;
} st;
int a1 ;
} ;
struct st obj ;
struct st obj1 ;
int main()
{
return obj.a1 + obj1.b ;
}
微软编译器Visual Studio 6.0编译程序成功。我对“struct st”的使用感到困惑。 obj 和 obj1 的大小是多少?
最佳答案
海湾合作委员会给
error: nested redefinition of ‘struct st’
error: ‘struct st’ has no member named ‘a1’
如果 VC6 编译它,那很好,但是这是无效的。
如果你想知道obj的大小,那就是sizeof obj
。我假设 VC6 只是将结构展平并为其分配了三个整数。
关于c - 奇怪的C程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1724251/