在引用内核代码时 here , struct page;
定义时没有成员(我猜这不是前向声明)。
但接受的答案在this帖子说这是不允许的。
然后我尝试了一个示例,
#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;
}
编译成功
empty_struct.c: In function ‘main’:
empty_struct.c:15:22: warning: unused variable ‘aa’ [-Wunused-variable]
请在这方面澄清我。
最佳答案
空结构与前向声明不同——空结构会有花括号,并且是不合法的。前向声明当然很好。
struct foo; // forward declaration - OK
struct bar { // empty struct - invalid
};
关于c - 没有成员的结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17335462/