【发布时间】:2015-08-23 21:37:10
【问题描述】:
在回答warning: assignment from incompatible pointer type for linklist array 时,我注意到任何带有struct 关键字的未声明标识符都被视为前向声明的标识符。
例如program below 编译良好:
/* 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 编译器将未声明的struct identifiers 视为前向声明的不完整struct 类型?
【问题讨论】:
-
我不知道,但可能是因为在声明
struct anything的过程中,您需要能够使用struct anything,也许编译器不会处理所有这些,而只是处理它是现有的吗?
标签: c struct c99 incomplete-type ansi-c