# include <stdio.h> typedef struct binode{ int a; struct binode *l; }binode; int main() { int a; int *p; binode s; printf("%d %d",sizeof(a),sizeof(s)); return 0; }结果正确:
4 8
# include <stdio.h>
typedef struct binode{
int a;
struct binode p;
}binode;
int main()
{
int a;
int *p;
binode s;
printf("%d %d",sizeof(a),sizeof(s));
return 0;
}
系统报错:
Line 5: error: field 'p' has incomplete type compilation terminated due to -Wfatal-errors.
通过以上测试可以看出。结构体在递归定义的时候可以定义本身,但是需要用指针,并且大小和结构体中的其他成员有关系。
如果用变量会出错,