Gamestudio Links
Zorro Links
Newest Posts
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
Data from CSV not parsed correctly
by jcl. 04/20/24 08:32
Zorro FIX plugin - Experimental
by jcl. 04/20/24 08:30
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (7th_zorro), 529 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 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,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
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