c - 奇怪的C程序

标签 c visual-studio

检查下面的代码片段

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/

相关文章:

c - 如何修复错误: incompatible types when returning type 'struct {aka struct <anonymous>}

从 ASCII 到 utf-16LE 的转换出现问题

.net - Windows 窗体应用程序的现代 UI 应用程序设计

c# - Visual Studio 和 Eclipse 哪个更好

visual-studio - 增加 Visual Studio 中 Cordova 构建的内存限制

为事件驱动应用程序选择 IPC 解决方案

c - 如何用 C 语言从文件中读取文本/数字

c - 如何告诉自动工具在不同的文件夹中使用不同的实现

Windows 上的 C++ - 控制台窗口闪烁并消失。这是怎么回事?

c# - xmlnodelist 到 C# 中的对象列表