Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
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
2 registered members (ozgur, TipmyPip), 722 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 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,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

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

Chief Engineer
jcl  Offline

Chief Engineer

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

Chief Engineer
jcl  Offline

Chief Engineer

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