Gamestudio Links
Zorro Links
Newest Posts
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
Release 2.68 replacement of the .par format
by Martin_HH. 09/23/25 20:48
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 18,161 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
How to return array from function? #468352
10/02/17 08:58
10/02/17 08:58
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
How can I return an array from a function?
This doesn't work...

Code:
bool[] initConditionArray(vars close, vars open, vars high, vars low) {
   
	bool conditionArray[100];
	
	conditionArray[0] = close[0] > close[1];
	conditionArray[1] = close[0] > close[2]);
        ....
}

void run {
        ...
        bool conditionsArray[100] = initConditionArray(close, open, high, low);
        ...
}


Re: How to return array from function? [Re: Dalla] #468355
10/02/17 09:32
10/02/17 09:32
Joined: Jul 2000
Posts: 28,022
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,022
Frankfurt
No, that does not work, but this would:

bool* initConditionArray(vars close, vars open, vars high, vars low) {

static bool conditionArray[100];

conditionArray[0] = close[0] > close[1];
conditionArray[1] = close[0] > close[2]);
....
return conditionArray;
}

void run {
...
bool* conditionsArray = initConditionArray(close, open, high, low);
...
}

Re: How to return array from function? [Re: jcl] #468360
10/02/17 10:28
10/02/17 10:28
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
Thanks!

Is it possible to know how big an array can be?
Reading the manual it says "In lite-C the stack has a limited size that is sufficient for many variables, but not for huge arrays".

Zorro crashes without any error message when I size my array as ~1500.

Re: How to return array from function? [Re: Dalla] #468363
10/02/17 11:01
10/02/17 11:01
Joined: Jul 2000
Posts: 28,022
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,022
Frankfurt
That's why large arrays should be global or static. If the stack size is exceeded, a program will crash with no error message. There's no function to get an array size, since an array variable is in fact a pointer. So you must store the size in an extra variable.

Re: How to return array from function? [Re: jcl] #468365
10/02/17 11:23
10/02/17 11:23
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
Hmm, but it crashes even if I create the array like this

Code:
static bool conditionArray[1760];


Re: How to return array from function? [Re: Dalla] #468368
10/02/17 12:21
10/02/17 12:21
Joined: Jul 2000
Posts: 28,022
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,022
Frankfurt
Maybe the crash has a different reason? 1760 bools is anyway not a really huge array. Can you post the whole script?


Re: How to return array from function? [Re: jcl] #468379
10/02/17 16:29
10/02/17 16:29
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
I solved my issue in another way. Realized that I didn't really need to create the array and all conditions on each new bar, so I now use a switch case statement instead which is a lot more efficient. And it has the benefit of not crashing ;-)


Moderated by  Petra 

Gamestudio download | 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