所有的结构标识符自动转发声明 [英] All struct identifiers are automatically forward declared
问题描述
虽然答案<一个href=\"http://stackoverflow.com/questions/30723241/warning-assignment-from-incompatible-pointer-type-for-linklist-array/30723317\">warning:从兼容的指针类型的链表数组赋值,我注意到结构
关键字perceded任何未声明的标识符被认为是向前声明标识符。
While answer warning: assignment from incompatible pointer type for linklist array, I noticed any undeclared identifier perceded with struct
keyword are considered as forward declared identifiers.
有关实例下的程序编译好:
For instance the program below compiles well:
/* 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
编译器把未申报结构标识符
参考译文]着不完整的申报结构
类型?
My question: Which rule guides a C
compiler to treat undeclared struct identifier
s as forward declared incomplete struct
types?
推荐答案
标准说( 6.2.5.28 )
所有指针结构类型应具有相同的重presentation和对齐要求对方。
All pointers to structure types shall have the same representation and alignment requirements as each other.
这意味着编译器知道如何重新present指针为任何的结构,即使是那些(还)不确定的。结果
只有指向这种结构您的程序交易,所以没关系。
This means the compiler knows how to represent the pointers to any structure, even those that are (yet) undefined.
Your program deals only with pointers to such structures, so it's ok.
这篇关于所有的结构标识符自动转发声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!