我使用gcc编译器编译下面的C码错误:编译器没有显示在未定义类型的声明指针
#include <stdio.h>
struct node{
int info;
struct test* next;
};
int main()
{
struct node start;
struct node* p;
start.info = 2;
start.next = (struct test*)&start;
printf("start.next = %p \n",start.next);
p = start.next;
printf("p->info = %d\n",p->info);
}
但想不到,宣告next
(在structure node
)作为指针不宣类型后( struct test
),仍然编译成功!上述程序编译后的印刷只是一个警告如下:
test.c:15:4: warning: assignment from incompatible pointer type [enabled by default]
p = start.next;
^
现在我的疑问是,为什么编译器不产生不声明structure test
错误?