linux code, about array initialization.

  • Thread starter Anonymousgoogledeja
  • Start date
A

Anonymousgoogledeja

hi all,

while I read the code from linux sources.

I read the statement

static const struct iw_ioctl_description standard_ioctl[] = {
[SIOCSIWCOMMIT - SIOCIWFIRST] = {
.header_type = IW_HEADER_TYPE_NULL,
},
...
};

I have never read such code. normaly, I will write the code as :

static const struct iw_ioctl_description standard_ioctl[] = {
{
.header_type = IW_HEADER_TYPE_NULL,
},
...
};

anyone would help me? thanks
 
K

Keith Thompson

Anonymousgoogledeja said:
while I read the code from linux sources.

I read the statement

static const struct iw_ioctl_description standard_ioctl[] = {
[SIOCSIWCOMMIT - SIOCIWFIRST] = {
.header_type = IW_HEADER_TYPE_NULL,
},
...
};

I have never read such code. normaly, I will write the code as :

static const struct iw_ioctl_description standard_ioctl[] = {
{
.header_type = IW_HEADER_TYPE_NULL,
},
...
};

The [SIOCSIWCOMMIT - SIOCIWFIRST] specifies an array index.
Presumably SIOCSIWCOMMIT-SIOCIWFIRST is an integer constant
expression.

By specifying the index values, you don't necessarily have to give the
array elements in order.
 
A

Anonymousgoogledeja

I wonder whether it's gcc specific or ANSI std specific?
Keith said:
Anonymousgoogledeja said:
while I read the code from linux sources.

I read the statement

static const struct iw_ioctl_description standard_ioctl[] = {
[SIOCSIWCOMMIT - SIOCIWFIRST] = {
.header_type = IW_HEADER_TYPE_NULL,
},
...
};

I have never read such code. normaly, I will write the code as :

static const struct iw_ioctl_description standard_ioctl[] = {
{
.header_type = IW_HEADER_TYPE_NULL,
},
...
};

The [SIOCSIWCOMMIT - SIOCIWFIRST] specifies an array index.
Presumably SIOCSIWCOMMIT-SIOCIWFIRST is an integer constant
expression.

By specifying the index values, you don't necessarily have to give the
array elements in order.
 
K

Keith Thompson

Anonymousgoogledeja said:
Keith said:
Anonymousgoogledeja said:
while I read the code from linux sources.

I read the statement

static const struct iw_ioctl_description standard_ioctl[] = {
[SIOCSIWCOMMIT - SIOCIWFIRST] = {
.header_type = IW_HEADER_TYPE_NULL,
},
...
};

I have never read such code. normaly, I will write the code as :

static const struct iw_ioctl_description standard_ioctl[] = {
{
.header_type = IW_HEADER_TYPE_NULL,
},
...
};

The [SIOCSIWCOMMIT - SIOCIWFIRST] specifies an array index.
Presumably SIOCSIWCOMMIT-SIOCIWFIRST is an integer constant
expression.

By specifying the index values, you don't necessarily have to give the
array elements in order.

I wonder whether it's gcc specific or ANSI std specific?

Please don't top-post. Your reply goes below the quoted text, so the
entire article can be read from top to bottom.

Designators in initializers (including both the ".member=value" and
"[index]=value" forms) are a new feature in C99. (The term "ANSI" is
ambiguous; strictly speaking the current 1999 ISO standard is the ANSI
standard, but the term "ANSI" is commonly used to refer to the
1989/1990 ANSI/ISO standard.)
 
E

Emmanuel Delahaye

Anonymousgoogledeja a écrit :
while I read the code from linux sources.

I read the statement

static const struct iw_ioctl_description standard_ioctl[] = {
[SIOCSIWCOMMIT - SIOCIWFIRST] = {
.header_type = IW_HEADER_TYPE_NULL,
},
...
};

I have never read such code. normaly, I will write the code as :

static const struct iw_ioctl_description standard_ioctl[] = {
{
.header_type = IW_HEADER_TYPE_NULL,
},
...
};

anyone would help me? thanks

Read again. 'iw_ioctl_description standard_ioctl' is an *array* of
structure... For an 'absolute' initializing (C99), you also need the index.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,170
Messages
2,570,925
Members
47,468
Latest member
Fannie44U3

Latest Threads

Top