Re: [Vala] how to declare multi-dimensional arrays in Genie?



 On 7/15/2010 6:50 PM, Jamie McCracken wrote:
On Thu, 2010-07-15 at 18:34 -0400, Ron Murawski wrote:
On 7/15/2010 1:45 PM, Robert Powell wrote:
Both of the above multi-dimensional array declarations work as
intended, but they do not seem to be global.

Is this what you are trying to do?

int [,] arr;

public void main(string [] args) {
     arr = new int[3,4];
     arr[0,0] = 1;
     arr[1,1] = 2;
     stderr.printf("%d:%d\n", arr[0,0], arr[1,1]);
}

Hope that helps
Thanks, Robert! That's exactly what I was trying to accomplish, but I was
trying to do it all at compile-time.

Hot diggety! I'm about to write a chess program in Genie! :-)


Here's Robert's example translated from Vala to Genie:

[indent=4]
//int [,] arr;
arr : array of int[,]  // declare array name with global scope

//public void main(string [] args) {
init
      //arr = new int[3,4];
      arr = new array of int[3,4]  // allocate the array
      arr[0,0] = 1;  // initialize it
      arr[1,1] = 2;
      stderr.printf("%d:%d\n", arr[0,0], arr[1,1]); // print it
//}



I want to make certain I am understanding this correctly:

1. All multi-dimensional arrays in Vala/Genie *must* be allocated at
run-time,
     not at compile-time

2. Optionally, the multi-dimensional array name can be declared a global
name


Is this correct?

if you mean you want to allocate multi dimensional arrays on the stack
like ordinary arrays then i dont know if vala supports that

If it does then it looks like a bug in Genie

jamie

I wanted the multi-dimensional array in the data area, not on the stack.

In C:

int my_array[64][13];

int main(int argc, **char argv)
{
    my_array[7][7] = 7;
    // more stuff
    return 0;
}

The space for the array is reserved by the C compiler at compile-time in the data area, the array is guaranteed to be zeroed, and the name 'my_array' is recognized globally by all modules, possibly with the help of extern statements.

I was trying to do the same in Vala/Genie, but this does not seem to be possible.

Best regards,
Ron



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]