User Tag List

Results 1 to 7 of 7

Thread: When declaring an Array...

  1. #1
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,303
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.64%

    When declaring an Array...

    If we can have
    Code:
    int MyArray[5] = {1,2,3,4,5};
    Then why can't we have
    Code:
    int a; int b; int c; int d; int e;
    int MyArray[5] = {a,b,c,d,e};
    ?

    The first one compiles fine, but the second doesn't.

  2. #2
    Developer
    ZC Developer
    jman2050's Avatar
    Join Date
    Jun 2001
    Location
    Do you really need to know
    Age
    37
    Posts
    3,883
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    5,708
    Level
    23
    vBActivity - Bars
    Lv. Percent
    46.05%

    Re: When declaring an Array...

    Heh, that isn't even allowed in C/C++ last I checked. I remember there being a reason they couldn't do it that way, though it escapes me.
    AGN's Resident Zelda Classic Developer and Sonic the Hedgehog Fanboy

  3. #3
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,303
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.64%

    Re: When declaring an Array...

    Oh, right ok.
    Fair enough.

    So
    Code:
    int a; int b; int c; int d; int e;
    int MyArray[5];
    MyArray[0] = a;
    MyArray[1] = b;
    //etc.
    is the most efficient method?

  4. #4
    Keese ScaryBinary's Avatar
    Join Date
    Dec 2006
    Age
    48
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    915
    Level
    10
    vBActivity - Bars
    Lv. Percent
    51.43%

    Re: When declaring an Array...

    Quote Originally Posted by Joe123 View Post
    So
    Code:
    int a; int b; int c; int d; int e;
    int MyArray[5];
    MyArray[0] = a;
    MyArray[1] = b;
    //etc.
    is the most efficient method?
    That will work, but I don't think it's going to do what you think it's going to do.

    (wait...what did I just say? )

    What I mean is, if you do that, and then do something like
    Code:
    a = 10;
    your array is not going to change - there is no "link" between the integer "a" and your array. So unless you are going to be constantly updating "a", "b" ... "e" and then pushing those values in to your array as in your snippet above, there's really no reason to declare/use the "a", "b" ... "e" variables. Just modify your array directly.

  5. #5
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,303
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.64%

    Re: When declaring an Array...

    What I think it's going to do is load some integers into an array.

    I have arguments in an ffc, and I want to load them into an array so I don't have to write out four lots of code.
    I know the array's not going to change, I only want to set it once.

  6. #6
    Keese ScaryBinary's Avatar
    Join Date
    Dec 2006
    Age
    48
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    915
    Level
    10
    vBActivity - Bars
    Lv. Percent
    51.43%

    Re: When declaring an Array...

    Gotcha.

    On an interesting side note, evidently you can only use positive numbers when you initialize an array at declaration. The following fails to compile (at least in build 819)...
    Code:
    int MyArray_1[5] = {0, 1, 2, -3, 4};
    You get an error on the minus sign.

  7. #7
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,303
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.64%

    Re: When declaring an Array...

    Might be linked to the fact that we can't declare negative constants?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social