Gamestudio Links
Zorro Links
Newest Posts
Z9 getting Error 058
by k_ivan. 04/20/26 15:57
Stooq now requires an API key
by jcl. 04/13/26 09:42
Strange "Alien" Skull created with >Knubber<
by NeoDumont. 04/10/26 18:58
400 free seamless texture pack downl. here !
by NeoDumont. 04/08/26 19:55
ZorroGPT
by TipmyPip. 04/08/26 17:08
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (Grant), 3,476 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
juergenwue, VladMak, Geir, ondrej, mredit
19208 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Test iterations are not independent #433135
11/25/13 02:52
11/25/13 02:52
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
I have an example of bleed between iterations of [Test].

Code:
var *r = NULL;
function main() {
  if (!r) {
  	r = malloc(sizeof(var));
  	*r = random();
  	printf("\nAssigning r=%f", *r);
  }
  printf("\nr=%f", *r);
}


Press [Test] twice. Output:
Code:
Zorro 1.16.4 Trading Automaton
Made with Gamestudio by oP group 2013


float compiling.............. ok

Assigning r=0.394250
r=0.394250

float run.. ok

r=0.394250


Observed: global var *r is not reset to NULL upon re-run of script.
Expected: Iterations to be independent.

Re: Test iterations are not independent [Re: GPEngine] #433144
11/25/13 08:52
11/25/13 08:52

A
acidburn
Unregistered
acidburn
Unregistered
A



Yes, this is quite an unexpected behaviour, and we all had to learn it the hard way. tongue But, it's a documented behaviour. You MUST initialize variables in the INITRUN phase!

http://manual.zorro-trader.com/run.htm

Re: Test iterations are not independent [Re: ] #433160
11/25/13 15:41
11/25/13 15:41
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
Thanks. Too bad if a program has a main() and not a run()?

Re: Test iterations are not independent [Re: GPEngine] #433161
11/25/13 16:00
11/25/13 16:00
Joined: Jul 2000
Posts: 28,093
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,093
Frankfurt
Global and static variables are used in many programming languages, and they always keep their values until the program exits.

In the case of Zorro, there is no main() function and a script is only exited when it's modified or a new script is selected. Clicking [Test] or [Result] do not exit the script. There are several good reasons for this, but it is indeed unexpected, especially when you're used to 'normal' programs that exit at the end of the main() function.


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