Kinda crude array pointer and dynamic tester.
The dynamic tester fails with -O optimisations.
Code: Select all
#macro __Arrayptr__(array)
Iif(Ubound(array,0)=1,@array(Lbound(array)), _
Iif(Ubound(array,0)=2,@array(Lbound(array,1),Lbound(array,2)), _
Iif(Ubound(array,0)=3,@array(Lbound(array,1),Lbound(array,2),Lbound(array,3)), _
Iif(Ubound(array,0)=4,@array(Lbound(array,1),Lbound(array,2),Lbound(array,3),Lbound(array,4)), _
Iif(Ubound(array,0)=5,@array(Lbound(array,1),Lbound(array,2),Lbound(array,3),Lbound(array,4),Lbound(array,5)), _
Iif(Ubound(array,0)=6,@array(Lbound(array,1),Lbound(array,2),Lbound(array,3),Lbound(array,4),Lbound(array,5),Lbound(array,6)), _
Iif(Ubound(array,0)=7,@array(Lbound(array,1),Lbound(array,2),Lbound(array,3),Lbound(array,4),Lbound(array,5),Lbound(array,6),Lbound(array,7)), _
Iif(Ubound(array,0)=8,@array(Lbound(array,1),Lbound(array,2),Lbound(array,3),Lbound(array,4),Lbound(array,5),Lbound(array,6),Lbound(array,7),Lbound(array,8)),0))))))))
#endmacro
#macro setptr(datatype,fname)
Function fname(a() As datatype,Byref ret As boolean=0) As datatype Ptr
Var z= __arrayptr__(a)
If z>@ret Then ret=true Else ret=false
Return z
End Function
#endmacro
Type udt
As Long n(100)
As String s
End Type
'setup four datatypes
setptr(Double,doubleptr)
setptr(String,stringptr)
setptr(udt,udtptr)
setptr(Short,shortptr)
Do
Scope
Dim As boolean b
Cls
Locate 5
Print "fn(ptr)","ptr","is dynamic?"
Redim As String st(1 To Rnd*5000) 'add random memory
If Rnd>.5 Then
Redim As Double d(4,5 To 7)
Print doubleptr(d(),b),@d(0,5),b,"dynamic"
Else
Dim As Double d(4,5 To 7)
Print doubleptr(d(),b),@d(0,5),b,"static"
End If
If Rnd>.5 Then
Redim As String s(-1 To 5,4,1 To 3,-3 To 4)
Print stringptr(s(),b),@s(-1,0,1,-3),b,"dynamic"
Else
Dim As String s(-1 To 5,4,1 To 3,-3 To 4)
Print stringptr(s(),b),@s(-1,0,1,-3),b,"static"
End If
If Rnd>.5 Then
Redim As udt z(2,3)
Print udtptr(z(),b),@z(0,0),b,"dynamic"
Else
Dim As udt z(2,3)
Print udtptr(z(),b),@z(0,0),b,"static"
End If
If Rnd>.5 Then
Redim As Short f(1 To 67,2 To 8)
Print shortptr(f(),b),@f(1,2),b,"dynamic"
Else
Dim As Short f(1 To 67,2 To 8)
Print shortptr(f(),b),@f(1,2),b,"static"
End If
Print "press a key or <esc>"
Sleep
End Scope
Loop Until Inkey=Chr(27)