Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (7th_zorro, degenerate_762, AndrewAMD, ozgur), 774 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 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: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
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: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
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: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

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