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
2 registered members (Grant, AndrewAMD), 911 guests, and 9 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
pointing to an array #203941
04/25/08 06:51
04/25/08 06:51
Joined: Aug 2004
Posts: 1,305
New York
PrenceOfDarkness Offline OP
Serious User
PrenceOfDarkness  Offline OP
Serious User

Joined: Aug 2004
Posts: 1,305
New York
I never would have thought I'd ever have to do something like this, but I guess the time has come and I can't seem to figure it out. Before you tell me to pick up a C++/C book let me say I've already tried that but they don't really explain it to clearily.

How do I point to an array? How would I then pass that pointer on to a function? I'd assumed it's just like every other pointer but I'm having problems. How can I change different array values using the pointer?

If you could give examples using the "var" variable type it would great.
If anyone knows a text I can find all theses answers in please let me know.


"There is no problem that can't be solved with time and determination." -me
prenceofdarkness for instant messages on AIM.

Looking for a model designer
PLEASE, SEND ME A PRIVATE MESSAGE OR EMAIL IF YOU'RE INTERESTED.
Re: pointing to an array [Re: PrenceOfDarkness] #203944
04/25/08 08:38
04/25/08 08:38
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
you're asking for two different things. pointers to arrays are, as arrays are in c nothing else but pointers to the first array element, pointers to pointers, e.g. var**. to pass an array, you don't need a pointer to the array but you can pass the array as-is, since it is already a pointer to the first array element, e.g. var*.

 Code:
var array[200]; // now array is a pointer to the first element of 200 allocated vars on the stack
var* array2 = array; // array2 can be accessed just like array
var test = array[5];
test = array2[5];

var** p_array = &array; // now you're pointing to a pointer to the first element
test = (*p_array)[5]; // you have to dereference it first, the following is also valid, but no good style and i'm not sure lite-c compiles it
test = p_array[0][5]; // #1 see below

...

void f(var* arr)
{
    var t = arr[5]; // keep care of your array bounds
}
void g(var** arr)
{
    var t = (*arr)[5]; // same as above, hope you get the idea
}

...

f(array);
f(array2);
f(*p_array);
g(&array);
g(&array2);
g(p_array);


multidimensional arrays lift the pointer level up accordingly, as twodimensional arrays are nothing else than pointers to pointers (see here #1).

joey.

btw. there are actually some differences. compilers usually allocate and deallocate pointers and arrays differently. so let's call them compatible here since we can use them both the same way.

Re: pointing to an array [Re: Joey] #204070
04/26/08 04:31
04/26/08 04:31
Joined: Aug 2004
Posts: 1,305
New York
PrenceOfDarkness Offline OP
Serious User
PrenceOfDarkness  Offline OP
Serious User

Joined: Aug 2004
Posts: 1,305
New York
wow... you made it so simple that I feel now like a total noob for even asking! You have no idea how much you just helped me and my game out! THANKS A MILLION!


"There is no problem that can't be solved with time and determination." -me
prenceofdarkness for instant messages on AIM.

Looking for a model designer
PLEASE, SEND ME A PRIVATE MESSAGE OR EMAIL IF YOU'RE INTERESTED.

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