Define and array initialisation

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

    Define and array initialisation

    Hi all,

    I have got a simple question about the
    #define command: Can I use it for array
    initialisation?

    E.g.

    #define ARRAYINIT { {0, 1}, {2,3} }

    ....
    int main ( void )
    {
    int somestuff[][] = ARRAYINIT;
    ...
    }

    Thanks,
    Michael

  • Alex Fraser

    #2
    Re: Define and array initialisation

    "Michael" <mic457@gmx.net > wrote in message
    news:ccgael$har $1@rzcomm2.rz.t u-bs.de...[color=blue]
    > I have got a simple question about the
    > #define command: Can I use it for array
    > initialisation?
    >
    > E.g.
    >
    > #define ARRAYINIT { {0, 1}, {2,3} }
    >
    > ...
    > int main ( void )
    > {
    > int somestuff[][] = ARRAYINIT;
    > ...
    > }[/color]

    Yep. After the preprocessing phase the source will read:

    ....
    int main ( void )
    {
    int somestuff[][] = { {0, 1}, {2,3} };
    ...
    }

    Alex


    Comment

    • Michael

      #3
      Re: Define and array initialisation

      Alex Fraser wrote:
      [color=blue]
      > Yep. After the preprocessing phase the source will read:
      >
      > ...
      > int main ( void )
      > {
      > int somestuff[][] = { {0, 1}, {2,3} };
      > ...
      > }
      >
      > Alex[/color]

      Hi Alex,

      thanks for the quick response.
      Regards
      Michael

      Comment

      • Emmanuel Delahaye

        #4
        Re: Define and array initialisation

        In 'comp.lang.c', "Alex Fraser" <me@privacy.net > wrote:
        [color=blue]
        > Yep. After the preprocessing phase the source will read:
        >
        > ...
        > int main ( void )
        > {
        > int somestuff[][] = { {0, 1}, {2,3} };
        > ...
        > }[/color]

        That is not C.

        int somestuff[][2] = { {0, 1}, {2,3} };

        --
        -ed- get my email here: http://marreduspam.com/ad672570
        The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
        C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
        FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/

        Comment

        • Emmanuel Delahaye

          #5
          Re: Define and array initialisation

          In 'comp.lang.c', Michael <mic457@gmx.net > wrote:
          [color=blue]
          > I have got a simple question about the
          > #define command: Can I use it for array
          > initialisation?
          >
          > #define ARRAYINIT { {0, 1}, {2,3} }
          > ...
          > int main ( void )
          > {
          > int somestuff[][] = ARRAYINIT;
          > ...
          > }[/color]

          Yes, but the dimensions of the array should be added

          int somestuff[2][2] = ARRAYINIT;

          only the lefmost dimension can be ommited :

          int somestuff[][2] = ARRAYINIT;

          --
          -ed- get my email here: http://marreduspam.com/ad672570
          The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
          C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
          FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/

          Comment

          • Michael

            #6
            Define and array initialisation - Yx1 Array

            > Yes, but the dimensions of the array should be added[color=blue]
            >
            > int somestuff[2][2] = ARRAYINIT;
            >
            > only the lefmost dimension can be ommited :
            >
            > int somestuff[][2] = ARRAYINIT;[/color]

            Hi,

            yeah, my compiler already complaint about that. But I got
            an other question. My compiler complains about an Yx1 array
            like:

            int somestuff[6][1] = { {1}, {1}, {1}, {1}, {1}, {1} };

            I know, I can do it with one dimension, but due the programm
            structure I would prefer to realize the above array.
            Is the a chance?
            Thanks,
            Michael

            Comment

            • Emmanuel Delahaye

              #7
              Re: Define and array initialisation - Yx1 Array

              In 'comp.lang.c', Michael <mic457@gmx.net > wrote:
              [color=blue]
              > My compiler complains about an Yx1 array
              > like:
              >
              > int somestuff[6][1] = { {1}, {1}, {1}, {1}, {1}, {1} };
              >
              > I know, I can do it with one dimension, but due the programm
              > structure I would prefer to realize the above array.[/color]

              or

              int somestuff[][1] = { {1}, {1}, {1}, {1}, {1}, {1} };

              Well, I don't see what does your compiler complain about. Sounds good to me.
              Must be something else.

              --
              -ed- get my email here: http://marreduspam.com/ad672570
              The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
              C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
              FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/

              Comment

              • Michael

                #8
                Re: Define and array initialisation - Yx1 Array

                Emmanuel Delahaye wrote:
                [...][color=blue]
                > Well, I don't see what does your compiler complain about. Sounds good to me.
                > Must be something else.
                >[/color]
                Exactly. You are right it was something else.
                Thanks again ....
                Michael

                Comment

                Working...