在利用typedef时,发现个奇怪的现象:
运行环境是code block
案例1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Vnode *ad;
struct Gnode
{
int nv;
int ne;
ad G[MAX];
};
struct Vnode
{
int x;
};
int main(void)
{
return 0;
}
没有报错,允许使用一个未定义的Vnode。
案例2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Vnode ad;
struct Gnode
{
int nv;
int ne;
ad G[MAX];
};
struct Vnode
{
int x;
};
int main(void)
{
return 0;
}
};
而这种清空下却不允许,提示error: array type has incomplete element type
下面代码调换顺序,先定义Vnode就没问题
案例3
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Vnode ad;
struct Vnode
{
int x;
};
struct Gnode
{
int nv;
int ne;
ad G[MAX];
};
int main(void)
{
return 0;
}
typedef是为一个已有类型起别名,那案例1为啥能成立?
求解,感激不尽。