May 25, 2022, 03:52:18 PM


Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........

Clearing local variables.

Started by Ionic Wind Support Team, November 27, 2006, 08:29:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ionic Wind Support Team

Original post by Fletchie on the Pyxia forums.  Works in Emergence:

The following function CL() - automatically clears/resets all local variables/strings/types in a subroutine to zero.

Call just after the 'defs' for the variables.

Can be useful if you have a lot of vars - and you need to make sure they're zero.

Don't use outside of a subroutine !!

type test
   def a:int
   def b:uint64
   def c:double
   def d:string
   def e:int
declare CL()
do:until inkey$<>""
sub TestClear(a:int,b:int)
def var1:int
def var2:double
def var3:char
def t:test
   'Comment out CL() to see the difference...
   print var1
   print var2
   print var3+0
   print t.a
   print t.b
   print t.c
   print len(t.d)
   print t.e
mov eax,esp            ; transfer esp to eax
add eax,16            ; add 16, skips the pushed EIP, esi,edi,ebx
xor edx,edx            ; Sets edx to zero
cmp eax,ebp            ; if eax equals ebp - we're done
je fincl
mov dword [eax],edx   ; clear 4 bytes
add eax,4
jmp loopcl            ; go-again

Ionic Wind Support Team