From: kernelcoder2 on 6 Jun 2010 03:06 Hi, I am a kernel newbie. Saw the following struct in linux kernel /net/ ipv4/tcp_ipv4.c: struct proto tcp_prot={ ..name = "TCP", ..owner = THIS_MODULE, .... } each field name starts with a dot, ends with a comma (,) instead of semicolon (;), this doesn't look like a C struct, what is it? Thanks. kc
From: pk on 6 Jun 2010 06:23 kernelcoder2 wrote: > Hi, > > I am a kernel newbie. Saw the following struct in linux kernel /net/ > ipv4/tcp_ipv4.c: > > struct proto tcp_prot={ > > .name = "TCP", > .owner = THIS_MODULE, > ... > } > > each field name starts with a dot, ends with a comma (,) instead of > semicolon (;), this doesn't look like a C struct, what is it? Thanks. It is NOT the declaration of a struct datatype; that was declared elsewhere. What you're seeing is the declaration of a variable of type "struct proto", using a syntax that allows for initialization of fields. Example: struct foo { int bar; int baz; }; struct foo x; x.bar = 10; x.baz = 20; The last three lines can also be written as struct foo x = { .bar = 10, .baz = 20 }; which is what you're seeing. It's allowed by C99.
|
Pages: 1 Prev: How to use nmap to discover IPs and mac addresses. Next: HOW2 hack Win-based pubic inet? |