我使用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
錯誤?