Structure declaration without its members variables

Valdis.Kletnieks at vt.edu Valdis.Kletnieks at vt.edu
Sun Apr 26 22:22:35 EDT 2015


On Mon, 27 Apr 2015 00:16:59 +0530, harshkdev said:

> struct kvm;
> struct kvm_vcpu;
>
> Generally we declare structure and its member at same place.

It's a forward declaration.

Consider two structures that have pointers to each other:

struct a {
      int b, c, d;
      struct *b b_ptr;
}

struct b {
	int foo, bar, baz;
	struct *a a_ptr;
}

Now, the struct *b in the first structure won't compile because it hasn't
seen b yet.  So we stick a 'struct b;' in front both of them so struct a can
compile successfully.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 848 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150426/def821f9/attachment.bin 


More information about the Kernelnewbies mailing list