小编Lee*_*Gom的帖子

C在定义之前声明结构

以下是问题的源代码:

#include <stdio.h>

typedef struct Foo
{
    int a;
    Bar b;
} Foo;

typedef struct Bar
{
    int a;
    int b;
} Bar;

int main(void)
{
    Foo f;
    f.a = 1;
    f.b.a = 2;
    f.b.b = 3;
    printf("%d %d %d\n", f.a, f.b.a, f.b.b);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我想在Bar结构中声明结构,该Foo结构保持结构声明的顺序(Foo结构是第一个).但我不能,它error: unknown type name 'Bar'在编译时发生了一些错误(一个是).

怎么做?

c struct

5
推荐指数
1
解决办法
3244
查看次数

标签 统计

c ×1

struct ×1