linux code, about array initialization.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anonymousgoogledeja

    #1

    linux code, about array initialization.

    hi all,

    while I read the code from linux sources.

    I read the statement

    static const struct iw_ioctl_descri ption 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_descri ption standard_ioctl[] = {
    {
    .header_type = IW_HEADER_TYPE_ NULL,
    },
    ...
    };

    anyone would help me? thanks

  • Keith Thompson

    #2
    Re: linux code, about array initialization.

    "Anonymousgoogl edeja" <asmboozer@hotm ail.com> writes:[color=blue]
    > while I read the code from linux sources.
    >
    > I read the statement
    >
    > static const struct iw_ioctl_descri ption 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_descri ption standard_ioctl[] = {
    > {
    > .header_type = IW_HEADER_TYPE_ NULL,
    > },
    > ...
    > };[/color]

    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_Keit h) kst-u@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.

    Comment

    • Anonymousgoogledeja

      #3
      Re: linux code, about array initialization.

      I wonder whether it's gcc specific or ANSI std specific?
      Keith Thompson wrote:[color=blue]
      > "Anonymousgoogl edeja" <asmboozer@hotm ail.com> writes:[color=green]
      > > while I read the code from linux sources.
      > >
      > > I read the statement
      > >
      > > static const struct iw_ioctl_descri ption 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_descri ption standard_ioctl[] = {
      > > {
      > > .header_type = IW_HEADER_TYPE_ NULL,
      > > },
      > > ...
      > > };[/color]
      >
      > 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_Keit h) kst-u@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.[/color]

      Comment

      • Keith Thompson

        #4
        Re: linux code, about array initialization.

        "Anonymousgoogl edeja" <asmboozer@hotm ail.com> writes:[color=blue]
        > Keith Thompson wrote:[color=green]
        >> "Anonymousgoogl edeja" <asmboozer@hotm ail.com> writes:[color=darkred]
        >> > while I read the code from linux sources.
        >> >
        >> > I read the statement
        >> >
        >> > static const struct iw_ioctl_descri ption 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_descri ption standard_ioctl[] = {
        >> > {
        >> > .header_type = IW_HEADER_TYPE_ NULL,
        >> > },
        >> > ...
        >> > };[/color]
        >>
        >> 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.[/color]
        >
        > I wonder whether it's gcc specific or ANSI std specific?[/color]

        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=va lue" 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_Keit h) kst-u@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.

        Comment

        • Emmanuel Delahaye

          #5
          Re: linux code, about array initialization.

          Anonymousgoogle deja a écrit :[color=blue]
          > while I read the code from linux sources.
          >
          > I read the statement
          >
          > static const struct iw_ioctl_descri ption 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_descri ption standard_ioctl[] = {
          > {
          > .header_type = IW_HEADER_TYPE_ NULL,
          > },
          > ...
          > };
          >
          > anyone would help me? thanks[/color]

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

          --
          C is a sharp tool

          Comment

          Working...