Menu

#92 Static array initializer wrong

OnBoard_C
open
nobody
OnBoard C (33)
5
2006-09-25
2006-09-25
No

When initializing a 2D array will incomplete lists,
the next list is loaded in the wrong spot.

<PRE>
Uint16 array2D[10]10] =
{
{1,2,3,4},
{5,6,7,8},
{9,0}
};
</PRE>

should load the array to be:
1 2 3 4 0 0 0 0 0 0
5 6 7 8 0 0 0 0 0 0
9 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
...

but instead loads it thusly:
1 2 3 4 5 6 7 8 9 0
0 0 0 0 0 0 0 0 0 0
...

Discussion

  • Jerramy Gipson

    Jerramy Gipson - 2006-09-25

    Logged In: YES
    user_id=1048900

    This may be related to bug 887312.

     
  • Jerramy Gipson

    Jerramy Gipson - 2006-09-26

    Logged In: YES
    user_id=1048900

    Another issue with this bit me. (I spent a significant
    amount of time looking in the wrong place for the fix...)

    If values are left off the list of initializers, the
    resulting structure in memory is the size of the list, not
    the size declared for the array. Thus:

    Uint16 array2D[10][10] =
    {{1,2,3},{4,5,6},{7,8}};

    is onlly 8 words long, instead of 100. Trying to assign to
    array2D[0][8] will result in memory corruption, and
    repeatedly crashed my Palm.

    However, I believe if you actually fill out the entire
    initializer list, or if you leave it off entirely, things
    are fine.

    Uint16 array2D[10][10];

    is in fact 100 words long.

     

Log in to post a comment.

MongoDB Logo MongoDB