2

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.

Community
  • 1
  • 1
Jeyaram
  • 9,158
  • 7
  • 41
  • 63

2 Answers2

8

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
};
Paul R
  • 208,748
  • 37
  • 389
  • 560
0

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

Chris Desjardins
  • 2,631
  • 1
  • 23
  • 25