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



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




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