Gamestudio Links
Zorro Links
Newest Posts
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (BrainSailor, 1 invisible), 1,090 guests, and 10 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
pass multidimensional array to function #173444
12/17/07 21:57
12/17/07 21:57
Joined: Mar 2007
Posts: 197
Y
yorisimo Offline OP
Member
yorisimo  Offline OP
Member
Y

Joined: Mar 2007
Posts: 197
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?


Joris Lambrecht
My Contributions: Relative Rotation, Window Sizing
Re: pass multidimensional array to function [Re: yorisimo] #173445
12/18/07 05:36
12/18/07 05:36
Joined: Oct 2006
Posts: 175
G
Gumby22don Offline
Member
Gumby22don  Offline
Member
G

Joined: Oct 2006
Posts: 175
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

Re: pass multidimensional array to function [Re: Gumby22don] #173446
12/18/07 09:03
12/18/07 09:03
Joined: Oct 2002
Posts: 8,939
planet.earth
ello Offline
Senior Expert
ello  Offline
Senior Expert

Joined: Oct 2002
Posts: 8,939
planet.earth
not so funky

Re: pass multidimensional array to function [Re: Gumby22don] #173447
12/18/07 21:55
12/18/07 21:55
Joined: Mar 2007
Posts: 197
Y
yorisimo Offline OP
Member
yorisimo  Offline OP
Member
Y

Joined: Mar 2007
Posts: 197
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.

Last edited by yorisimo; 12/18/07 21:56.

Joris Lambrecht
My Contributions: Relative Rotation, Window Sizing
Re: pass multidimensional array to function [Re: yorisimo] #173448
12/19/07 11:58
12/19/07 11:58
Joined: Jul 2000
Posts: 27,987
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,987
Frankfurt
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.

Re: pass multidimensional array to function [Re: Gumby22don] #463899
01/04/17 20:14
01/04/17 20:14
Joined: Jan 2017
Posts: 2
V
vas Offline
Guest
vas  Offline
Guest
V

Joined: Jan 2017
Posts: 2
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?

Last edited by vas; 01/04/17 20:14.

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1