Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, Grant, Neb), 908 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
MultiDimensional array helper macro/function [solved] #386451
11/03/11 07:57
11/03/11 07:57
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Hiya all. Im doing some heavy work with pseudo-multi-dimensional arrays at the moment.

I have done a LOT of coding with it as actual multi-dimensional array,
but its just getting to tricky down in the guts, and the code LOOKS ugly,
because of all the bracketing required around them...
(ie (slabs[x])[y].element = xxx; )

Therefore Ive decided to simplify and go for a single-dimension array that I reference
AS IF it was multi-dimensional.
(ie slabs[x+y*width].element = xxx; )
This re-codeing of pages and pages of script is what Im working on now...


BUT, Im looking for a 'shortcut' with the referencing, to try to tidy my code.

Ive tryed a few variations of THIS
Code:
SLAB** slabs = (SLAB**)sys_malloc(sizeof(SLAB*)*???);

SLAB*	slab(int x, int y)	{	return(slabs[x+y*slab_len]);	}

//attempted usage
slab(x,y).LOD = 123;               and/or      xyz = slab(x,y).LOD;

//which is to replace
slabs[x+y*slab_len].LOD = 123;     and/or      xyz = slabs[x+y*slab_len].LOD;

//which in the process of replacing
(slabs[x])[y].LOD = 123;           and/or      xyz = (slabs[x])[y].LOD;



So can you see what I want? Have I explained this properly?

I am hoping someone has some ideas for a macro, function, or macro/function combo
that will let me access my array on BOTH sides of the equals sign using a simple
slab(x,y) string in my scripts...

Thanks Guys




Last edited by EvilSOB; 11/03/11 08:20.

"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: MultiDimensional array helper macro/function [solved] [Re: EvilSOB] #386454
11/03/11 08:26
11/03/11 08:26
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Dont worry guys... I got it pegged.

Code:
SLAB*	slab_ref(int x, int y)  {  return(slabs[x+y*slab_len]);  }
#define	slab(x,y)   slab_ref(x,y))



Works just as I had hoped.

Just wish it could have worked with SQUARE brackets... ie slab[x,y] ...
Oh well...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: MultiDimensional array helper macro/function [solved] [Re: EvilSOB] #386457
11/03/11 09:03
11/03/11 09:03
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Why don't you use this?
Code:
#define slab(x,y) slabs[x+y*slab_len]




Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: MultiDimensional array helper macro/function [solved] [Re: WretchedSid] #386465
11/03/11 11:25
11/03/11 11:25
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
It didnt work, ut this does...
Code:
#define slab(x,y) slabs[(x)+(y)*slab_len]



I dont know WHY I didnt try this before... Too damn obvious maybe...

Or perhaps cause I started trying with functions, and couldnt let them go...


I dunno, but thanks man. This is MUCH cleaner, and much more trustworthy.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

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