By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,434 Members | 1,878 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,434 IT Pros & Developers. It's quick & easy.

linux code, about array initialization.

P: n/a
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

Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Anonymousgoogledeja" <as*******@hotmail.com> writes:
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #2

P: n/a
I wonder whether it's gcc specific or ANSI std specific?
Keith Thompson wrote:
"Anonymousgoogledeja" <as*******@hotmail.com> writes:
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


Nov 15 '05 #3

P: n/a
"Anonymousgoogledeja" <as*******@hotmail.com> writes:
Keith Thompson wrote:
"Anonymousgoogledeja" <as*******@hotmail.com> writes:
> 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.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #4

P: n/a
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.

--
C is a sharp tool
Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.