正如其他人所说,您编写代码的方式不会构建。您应该收到如下所示的错误:
typedef struct
{
int day;
} Date;
typedef struct
{
struct Date;//Error here - Undefined size for field, incomplete struct Date defined at cfile.c:8
} Insert;
Insert insert;
int main(void)
{
return 0;
}
您已经创建了一个类型Date
(即typedef struct
...Date
),请使用它而不是struct Date;
这样:( 这将构建)
#include <ansi_c.h>
typedef struct
{
int day;
} Date;//you have just created a new type: struct Date here..., use "Date date;" below, (not struct Date;)
typedef struct
{
Date date;//"Date is a type (typedef struct Date), so use it here to declare the member "date"
} Insert;
Insert insert;
int main(void)
{
return 0;
}
int main(void)
{
scanf("%d", &insert.date.day);
return 0;
}