From: kernelcoder2 on
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
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.