IonicWind Software

Aurora Compiler => General Discussion => Topic started by: Haim on December 07, 2006, 12:26:22 AM

Title: How to assign elements of a two dimensional array?
Post by: Haim on December 07, 2006, 12:26:22 AM
Hi,
In the aurora tutorial there is an example of how to declare and assign a single dimensioned array of an intrinsic type (by a comma separated list of the values)

Is it possible to initialize and assign in this way arrays with 2 or 3 dimensions?
Is it possible to do that with arrays of simple structures (such as an array of POINT)?

This is not terribly important, but may save on a lot of typing...

Haim
Title: Re: How to assign elements of a two dimensional array?
Post by: Bruce Peaslee on December 07, 2006, 10:15:35 AM
Try this:


sub main()
{
int myArray[3,3]; // 9 elements
int i;
int j;

myArray = 1,2,3,4,5,6,7,8,9;

openconsole();
for(j = 0; j < 3; j++)
{
for(i = 0; i < 3; i++)
{
print(myArray[i,j]);
}
}
while GetKey()=="";
closeconsole();
}
Title: Re: How to assign elements of a two dimensional array?
Post by: Haim on December 08, 2006, 01:10:04 AM
Thanks,

I could not figure out though if this can be done with a structure such as POINT.

point pt[3];

can I assign like this: pt=......

Haim
Title: Re: How to assign elements of a two dimensional array?
Post by: Ionic Wind Support Team on December 08, 2006, 01:26:40 AM
The short answer is you can't.  However if all of the elements of a structure are the same size, and the struture size is a multiple of 4, there is a way to trick the compiler into doing it.


sub main()
{
POINT pt[10];
*(int)&pt = 1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10;
for(int x=0;x < 10;x++)
{
print( pt[x].x,",",pt[x].y );
}
while GetKey()="";
}


This works with a point structure because it is comprized of two integer elements and the structure size is 8.

Paul.