Reputation: 9474
While refering kernel code here, 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.
Upvotes: 2
Views: 308
Reputation: 212969
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
};
Upvotes: 8
Reputation: 2720
It is a forward decl, here is where it is defined:
http://lxr.free-electrons.com/source/include/linux/mm_types.h?v=3.4
Upvotes: 0