#79379 - 2003-01-08 06:27 PM
iif() stack overflow exception "problem"?
|
Lee Wilmott
Starting to like KiXtart
Registered: 2002-09-17
Posts: 106
Loc: Bristol, UK
|
I am using KiX version 4.20 Beta 1.
I wrote the following Exp() function some time ago which I find very helpful for use with binary bit manipulation.
code:
Function Exp($Base, $Power) ;Returns a base value raised to the specified power If $Power = 0 $Exp = 1 Else $Exp = Exp($Base, $Power - 1) * $Base EndIf EndFunction
Anyway, since the release of 4.20 albeit Beta, I thought I could re-write it using the new iif() function.
However, the following code produces a "Stack overflow exception" error...
code:
Function Exp2($Base, $Power) ;Returns a base value raised to the specified power $Exp2 = iif($Power = 0, 1, Exp2($Base, $Power - 1) * $Base) EndFunction
Admittedly the function names are different (so I could test them in the same script file), but aren't these two functions programatically identical?
Should I be receiving "Stack Overflow" errors?
Lee
|
Top
|
|
|
|
#79381 - 2003-01-08 07:02 PM
Re: iif() stack overflow exception "problem"?
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
Lee,
I just converted your UDF to VBS and was utterly shocked when I got exactly the same error !!! Would have bet the farm that this was a bug.
C:\t.vbs(8, 2) Microsoft VBScript runtime error: Out of stack space: 'Exp'
Heres the code:
code:
WScript.Echo Exp(5,5) Function Exp(Base, Power) ' Returns a base value raised to the specified power Exp = IIF(Power = 0, 1, Exp(Base, Power - 1) * Base) ' If Power = 0 Then ' Exp = 1 ' Else ' Exp = Exp(Base, Power - 1) * Base ' End If End Function
There must be more going on here than meets the eye !!!
-Shawn [ 08. January 2003, 19:02: Message edited by: Shawn ]
|
Top
|
|
|
|
#79382 - 2003-01-08 07:04 PM
Re: iif() stack overflow exception "problem"?
|
Lee Wilmott
Starting to like KiXtart
Registered: 2002-09-17
Posts: 106
Loc: Bristol, UK
|
Shawn,
I didn't think of testing it with VB!
Anyway, yeah that is interesting.
Do I assume that you guys agree with me? - this shouldn't return a stack overflow error!
Lee
|
Top
|
|
|
|
#79391 - 2003-01-08 08:08 PM
Re: iif() stack overflow exception "problem"?
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
Heres another proof I guess:
code:
break on $x = iif(1=1,FuncOne(),FuncTwo()) exit 1 function FuncOne() ?"FuncOne..." endfunction function FuncTwo() ?"FuncTwo..." endfunction
Output is:
code:
C:\>kix32 t
FuncOne... FuncTwo...
[ 08. January 2003, 20:11: Message edited by: Shawn ]
|
Top
|
|
|
|
#79394 - 2003-01-08 10:10 PM
Re: iif() stack overflow exception "problem"?
|
Lee Wilmott
Starting to like KiXtart
Registered: 2002-09-17
Posts: 106
Loc: Bristol, UK
|
Interesting topic - I think!
Shawn,
Your earlier example...
quote:
code:
$x = iif(1=1,FuncOne(),FuncTwo())
Which display's the two strings defined in BOTH functions really surprised me!
I 100% agree with you, iif() is clearly NOT the same as if ... else ... .
Although I see no reason why this shouldn't work - I also believe that KiX should perform in the same way that VB does - for interoperability reasons if nothing else.
Having said all that, I would be very interested in Ruud's views on this matter.
Lee
|
Top
|
|
|
|
#79398 - 2003-01-08 11:19 PM
Re: iif() stack overflow exception "problem"?
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
So really all IIF really is is this:
code:
Break On $x = IIF2(1=1,1+1,2+2) Exit 1 Function IIF2($x,$y,$z) If $x $IIF2=$y Else $IIF2=$z EndIf EndFunction
And to my mind, IIF is only really usefull for quick one-shot conditional assignments - using throw-away expressions. Comments ? [ 09. January 2003, 01:25: Message edited by: Shawn ]
|
Top
|
|
|
|
Moderator: ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
0 registered
and 370 anonymous users online.
|
|
|