Gamestudio Links
Zorro Links
Newest Posts
Why Zorro supports up to 72 cores?
by 11honza11. 04/26/24 08:55
M1 Oversampling
by 11honza11. 04/26/24 08:32
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, VoroneTZ, Quad, 1 invisible), 837 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Switch case - limit to number of cases? #468904
10/26/17 19:10
10/26/17 19:10
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
Hi,

I have a HUGE switch case statement with more than 2000 cases.
It seems like once I go above 2090 switch statements, my script crashes.

Is this a known limit?

I´ve tried debugging with verbose = 31, but there´s nothing in the log really except the crash.

Re: Switch case - limit to number of cases? [Re: Dalla] #468907
10/26/17 21:16
10/26/17 21:16
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
The attached script uses a switch with 3000 elements and it works fine.

Isolate your switch and figure out what's messed up.

Attached Files
bigswitch.c (9 downloads)
Re: Switch case - limit to number of cases? [Re: AndrewAMD] #468908
10/26/17 23:54
10/26/17 23:54
Joined: Sep 2017
Posts: 235
H
Hredot Offline
Member
Hredot  Offline
Member
H

Joined: Sep 2017
Posts: 235
I usually get a crash when I try to access more data into the past than I reserved in LookBack variable. Just a possibility! =)

Re: Switch case - limit to number of cases? [Re: Hredot] #468909
10/27/17 07:30
10/27/17 07:30
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
Well, in my case this works

Code:
case 2073: return closeDevMA10N[0] < 0.0; break;
	case 2074: return closeDevMA10N[0] < -0.2; break;
	case 2075: return closeDevMA10N[0] < -0.4; break;
	case 2076: return closeDevMA10N[0] < -0.6; break;
	case 2077: return closeDevMA10N[0] < -0.8; break;
	
        ....
	case 2088:  
	case 2089: 
	case 2090: return true; break;



while this does not
Code:
case 2073: return closeDevMA10N[0] < 0.0; break;
	case 2074: return closeDevMA10N[0] < -0.2; break;
	case 2075: return closeDevMA10N[0] < -0.4; break;
	case 2076: return closeDevMA10N[0] < -0.6; break;
	case 2077: return closeDevMA10N[0] < -0.8; break;
	
        ....
	case 2088:  
	case 2089: 
	case 2090: 
	case 2091: return true; break;



So basically adding one more switch statement crashes the script

Re: Switch case - limit to number of cases? [Re: Dalla] #468911
10/27/17 10:18
10/27/17 10:18
Joined: Oct 2008
Posts: 681
Germany
Ayumi Offline
User
Ayumi  Offline
User

Joined: Oct 2008
Posts: 681
Germany
You do not need any break with return...and btw, so many cases are bad programming.

EDIT:
I remember this thread. Maybe it's the same ....
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=467181#Post467181

Last edited by Ayumi; 10/27/17 10:23.
Re: Switch case - limit to number of cases? [Re: Ayumi] #468919
10/27/17 14:00
10/27/17 14:00
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
Probably it is, but still doesn´t explain why it would crash.

Unfortunately I don't know german...

Re: Switch case - limit to number of cases? [Re: Dalla] #468921
10/27/17 15:04
10/27/17 15:04
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
It is not necessary to know German. Summary: your function is too large. Large functions are bad programming practice.

You have many good alternatives. Here's one:
* Use a csv file to store your long list of values.
* When the script starts, load the csv file into a var array or struct array.
* Pull values from your array as needed.

Re: Switch case - limit to number of cases? [Re: AndrewAMD] #468961
10/30/17 10:28
10/30/17 10:28
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
The summary of the German thread: For statements like if, while, switch, etc. the compiler generates an internal jump table on the stack. Which means that the stack, since it is finite, can overflow at some point, dependent on what else is on the stack.

This has no relevance for real programming since no one would ever have 2000 nested if() clauses or a switch with 2000 cases... or so I thought. But apparently lite-C programmers break all sorts of strange code records.

Conclusion: Code in a reasonable way.

Re: Switch case - limit to number of cases? [Re: jcl] #468964
10/30/17 11:09
10/30/17 11:09
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
Got it :-)


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