1. Depth limit to nested for loops
- Posted by Fernando Bauer <fmbauer at hotmai?.?om> Jun 03, 2008
- 613 views
Kat wrote: > > Derek Parnell wrote: > > > > Kat wrote: > > > > > What is the depth limit to nested for/while loops in Eu? > > > > I think it is only limited by available memory. There is no hard-coded > > limit. > > When you say "available memory", would that be 1Kbytes local stack space per > procedure, or 64k global stack space, or the 2 gigabytes the OS will let the > program have? Or somewhere in between that's undefined? > > Yes, real world, i hit TurboPascal's stack limit with nested loops. > > Kat I tested two cases with exwc 3.0.2 (WinXP SP2): a) At top-level:
integer fn,r,depth depth = 0 r = 0 while r = 0 do depth += 1 position(1,1) printf(1,"Depth: %d ",depth) fn = open("nesttst.exw","w") puts(fn,"integer a a = 0\n") for i = 1 to depth do printf(fn,"for a%d=%d to %d do a += 1\n",i) end for for i = 1 to depth do printf(fn,"end for\n",i) end for puts(fn,"? a") close(fn) r = system_exec("exwc nesttst.exw",2) end while printf(1,"\nMaximum depth of nested 'for':%d\n",depth-1) printf(1,"Return value at system_exec:%d\n",r)
Result: Depth: 2696 A stack overflow was encountered at address 7c90edde Maximum depth of nested 'for':2695 Return value at system_exec:-1073741819 b) Inside a procedure:
integer fn,r,depth depth = 0 r = 0 while r = 0 do depth += 1 position(1,1) printf(1,"Depth: %d ",depth) fn = open("nesttst.exw","w") puts(fn,"integer a a = 0\nprocedure test()\n") for i = 1 to depth do printf(fn,"for a%d=%d to %d do a += 1\n",i) end for for i = 1 to depth do printf(fn,"end for\n",i) end for puts(fn,"? a\n") puts(fn,"end procedure\ntest()") close(fn) r = system_exec("exwc nesttst.exw",2) end while printf(1,"\nMaximum depth of nested 'for':%d\n",depth-1) printf(1,"Return value at system_exec:%d\n",r)
Result: Depth: 2784 2783 Maximum depth of nested 'for':2783 Return value at system_exec:-1073741819 In this case (depth=2784), the program doesn't show error message, but, strangely, it doesn't show the value of 'a'. Regards, Fernando
2. Re: Depth limit to nested for loops
- Posted by Jason Gade <jaygade at yah?o?com> Jun 03, 2008
- 567 views
Fernando Bauer wrote: > > Kat wrote: > > > > Derek Parnell wrote: > > > > > > Kat wrote: > > > > > > > What is the depth limit to nested for/while loops in Eu? > > > > > > I think it is only limited by available memory. There is no hard-coded > > > limit. > > > > When you say "available memory", would that be 1Kbytes local stack space per > > procedure, or 64k global stack space, or the 2 gigabytes the OS will let the > > program have? Or somewhere in between that's undefined? > > > > Yes, real world, i hit TurboPascal's stack limit with nested loops. > > > > Kat > > I tested two cases with exwc 3.0.2 (WinXP SP2): > > a) At top-level: > > }}} <eucode> > integer fn,r,depth > depth = 0 > r = 0 > while r = 0 do > depth += 1 > position(1,1) > printf(1,"Depth: %d ",depth) > fn = open("nesttst.exw","w") > puts(fn,"integer a a = 0\n") > for i = 1 to depth do > printf(fn,"for a%d=%d to %d do a += 1\n",i) > end for > for i = 1 to depth do > printf(fn,"end for\n",i) > end for > puts(fn,"? a") > close(fn) > r = system_exec("exwc nesttst.exw",2) > end while > printf(1,"\nMaximum depth of nested 'for':%d\n",depth-1) > printf(1,"Return value at system_exec:%d\n",r) > </eucode> {{{ > > Result: > Depth: 2696 A stack overflow was encountered at address 7c90edde > Maximum depth of nested 'for':2695 > Return value at system_exec:-1073741819 > > b) Inside a procedure: > > }}} <eucode> > integer fn,r,depth > depth = 0 > r = 0 > while r = 0 do > depth += 1 > position(1,1) > printf(1,"Depth: %d ",depth) > fn = open("nesttst.exw","w") > puts(fn,"integer a a = 0\nprocedure test()\n") > for i = 1 to depth do > printf(fn,"for a%d=%d to %d do a += 1\n",i) > end for > for i = 1 to depth do > printf(fn,"end for\n",i) > end for > puts(fn,"? a\n") > puts(fn,"end procedure\ntest()") > close(fn) > r = system_exec("exwc nesttst.exw",2) > end while > printf(1,"\nMaximum depth of nested 'for':%d\n",depth-1) > printf(1,"Return value at system_exec:%d\n",r) > </eucode> {{{ > > Result: > Depth: 2784 2783 > Maximum depth of nested 'for':2783 > Return value at system_exec:-1073741819 > > In this case (depth=2784), the program doesn't show error message, but, > strangely, > it doesn't show the value of 'a'. > > Regards, > Fernando Wow, an actual experiment. Well done! -- A complex system that works is invariably found to have evolved from a simple system that works. --John Gall's 15th law of Systemantics. "Premature optimization is the root of all evil in programming." --C.A.R. Hoare j.
3. Re: Depth limit to nested for loops
- Posted by Matt Lewis <matthewwalkerlewis at ?mail.co?> Jun 03, 2008
- 576 views
Fernando Bauer wrote: > > > > Kat wrote: > > > > > > > What is the depth limit to nested for/while loops in Eu? > I tested two cases with exwc 3.0.2 (WinXP SP2): > > a) At top-level: > Result: > Depth: 2696 A stack overflow was encountered at address 7c90edde > Maximum depth of nested 'for':2695 > Return value at system_exec:-1073741819 > > b) Inside a procedure: > Result: > Depth: 2784 2783 > Maximum depth of nested 'for':2783 > Return value at system_exec:-1073741819 > > In this case (depth=2784), the program doesn't show error message, but, > strangely, > it doesn't show the value of 'a'. If you're using a compiled interpreter, then the interpretation will cause a stack overflow, since it will basically call Statement_list() recursively. Matt