[英]Struct with no member
While refering kernel code here , struct page;
在这里引用内核代码时,
struct page;
is defined with no member(I Guess this is not a forward declaration). 没有成员定义(我猜这不是前瞻性声明)。
But the accepted answer in this post says it is not allowed. 但是这篇文章中接受的答案是不允许的。
Then i tried a sample, 然后我试了一个样本,
#include <stdio.h>
struct page;
struct arm_vmregion
{
unsigned long vm_start;
unsigned long vm_end;
struct page *vm_pages;
int vm_active;
const void *caller;
};
int main()
{
struct arm_vmregion aa;
return 0;
}
It compiles successfully 它编译成功
empty_struct.c: In function ‘main’:
empty_struct.c:15:22: warning: unused variable ‘aa’ [-Wunused-variable]
Please clarify me in this regard. 请在这方面澄清一下。
An empty struct is not the same as a forward declaration - an empty struct would have braces, and would not be legal. 空结构与前向声明不同 - 空结构将具有大括号,并且不合法。 Forward declarations are fine of course.
前瞻性声明当然可以。
struct foo; // forward declaration - OK
struct bar { // empty struct - invalid
};
It is a forward decl, here is where it is defined: 它是一个前向decl,这里定义它:
http://lxr.free-electrons.com/source/include/linux/mm_types.h?v=3.4 http://lxr.free-electrons.com/source/include/linux/mm_types.h?v=3.4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.