在回答警告:从不兼容的指针类型为链接列表数组赋值时,我注意到任何带有struct
关键字的未声明标识符都被视为前向声明的标识符。
例如下面的程序编译得很好:
/* Compile with "gcc -std=c99 -W -Wall -O2 -pedantic %" */
#include <stdio.h>
struct foo
{
struct bar *next; /* Linked list */
};
int main(void) {
struct bar *a = 0;
struct baz *b = 0;
struct foo c = {0};
printf("bar -> %p\n", (void *)a);
printf("baz -> %p\n", (void *)b);
printf("foo -> %p, %zu\n", (void *)&c, sizeof c); /* Remove %zu if compiling with -ansi flag */
return 0;
}
我的问题:哪个规则指导C
编译器将 undeclared struct identifier
s 视为前向声明的不完整struct
类型?