【发布时间】:2014-09-26 06:58:02
【问题描述】:
我使用 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(in structure node) 声明为指向未声明类型(struct test) 的指针后,编译仍然成功!!!编译上述程序后,仅打印如下警告:
test.c:15:4: warning: assignment from incompatible pointer type [enabled by default]
p = start.next;
^
现在我的疑问是为什么编译器没有因为未声明 structure test 而产生错误?
【问题讨论】:
标签: c pointers gcc declaration