pass multidimensional array to function

Posted By: yorisimo

pass multidimensional array to function - 12/17/07 21:57

How do you pass a multidimensional array to a function in Lite-C?

I want to pass a 3x3 matrix to a function, and I'd like to use multidimensional arrays instead of using the C-script method.

I've tried with the following function prototypes:
1. function load_matrix(var* M); <--this works with single dimensional arrays
2. function load_matrix(var** M);
3. function load_matrix(var M[][]);
4. function load_matrix(var M[][3]);
5. function load_matrix(var M[3][3]);

1-2: dimension of array error
3-5: syntax error

Any Ideas?
Posted By: Gumby22don

Re: pass multidimensional array to function - 12/18/07 05:36

lite-c still doesn't support [x][y] multi-dimensioned arrays. You need to use [x*max_y + y] - whether you make a custom function to take the x,y and return the single address, or just use that formula all the time is up to you.

Check the manual

Don
have a great day
Posted By: ello

Re: pass multidimensional array to function - 12/18/07 09:03

not so funky
Posted By: yorisimo

Re: pass multidimensional array to function - 12/18/07 21:55

from the manual:
Quote:


LC In lite-C, you can also define and address multidimensional arrays by using several indices:

var heightmap[10][20];...
heightmap[j][k] = 10; // j = 0..9, k = 0..19





Lite-C does support this. And I have used this method. However, I can't seem to pass it to a function.
Posted By: jcl

Re: pass multidimensional array to function - 12/19/07 11:58

You can not use arrays or structs as arguments to a function. Functions only accept and return variables and pointers.

An array is the same as a pointer, so this

function load_matrix(var* M);

works for multidimensional arrays just the same way as for a single dimensional array. However for accessing the array members within a function, you still need the [x*max_y + y] approach because the function can not know the dimensions of your array.

Hope this helps.
Posted By: vas

Re: pass multidimensional array to function - 01/04/17 20:14

Originally Posted By: Gumby22don
lite-c still doesn't support [x][y] multi-dimensioned arrays. You need to use [x*max_y + y] - whether you make a custom function to take the x,y and return the single address


So, is there any improvement in lite-c multi-dimensioned arrays?
© 2024 lite-C Forums