I'll let my crude method be my answer to the challenge.
Maybe other methods will unfold in due course.
Here I test the crude method under looping.
Any overwriting of true or false will show with draw string.
Tested gas, gcc, 32 and 64 bits optimised -O3 and un optimized.
Code: Select all
#macro TypeHasDtor(TypeSymbol, TypeHasDtorResult)
randomize
type udt##typesymbol
as typesymbol x
end type
dim as integer Num##typesymbol=2000+int(rnd*10000) 'arbitrary size
dim as integer ptr p0##typesymbol=new integer[1] 'address 0
dim as udt##typesymbol ptr p1##typesymbol=new udt##typesymbol[Num##typesymbol] 'address 1
dim as integer x##typesymbol= (cint(p1##typesymbol)-cint(p0##typesymbol))/sizeof(integer)
'print x##typesymbol
TypeHasDtorResult=iif(x##typesymbol and 1,true,false) 'if difference is odd then true
delete[] p1##typesymbol
delete[] p0##typesymbol
#endmacro
'looper
#macro TypeHasDtorrun(TypeSymbol, TypeHasDtorResult)
Num##typesymbol=10+rnd*50 'an arbitrary number of instances
p0##typesymbol=new integer[1]
p1##typesymbol=new udt##typesymbol[Num##typesymbol]
x##typesymbol= (cint(p1##typesymbol)-cint(p0##typesymbol))/sizeof(integer)
TypeHasDtorResult=iif(x##typesymbol and 1,true,false) 'if difference is odd then true
delete[] p1##typesymbol
delete[] p0##typesymbol
#endmacro
Dim As boolean hasDtorResult
TypeHasDtor(Integer, hasDtorResult)
Print "The 'Integer' Type has a destructor (implicit or explicit): ", hasDtorResult
TypeHasDtor(String, hasDtorResult)
Print "The 'String' Type has a destructor (implicit or explicit): ", hasDtorResult
Type string10Type As String * 10 '' define an alias to get a symbol name
TypeHasDtor(string10Type, hasDtorResult)
Print "The 'String * 10' Type has a destructor (implicit or explicit): ", hasDtorResult
Type stringptrType As String Ptr '' define an alias to get a symbol name
TypeHasDtor(stringptrType, hasDtorResult)
Print "The 'String Ptr' Type has a destructor (implicit or explicit): ", hasDtorResult
TypeHasDtor(Object, hasDtorResult)
Print "The 'Object' Type has a destructor (implicit or explicit): ", hasDtorResult
Type UDT1 Extends Object
End Type
TypeHasDtor(UDT1, hasDtorResult)
Print "The 'UDT1' User-Type has destructor (implicit or explicit): ", hasDtorResult
Type UDT2 Extends Object
Declare Destructor ()
End Type
Destructor UDT2 ()
End Destructor
TypeHasDtor(UDT2, hasDtorResult)
Print "The 'UDT2' User-Type has destructor (implicit or explicit): ", hasDtorResult
'====================================
screen 19
dim as long counter
do
counter+=1
TypeHasDtorRun(Integer, hasDtorResult)
draw string(0,30), "The 'Integer' Type has a destructor (implicit or explicit): " & hasDtorResult
TypeHasDtorRun(String, hasDtorResult)
draw string(0,50), "The 'String' Type has a destructor (implicit or explicit): "& hasDtorResult
TypeHasDtorRun(string10Type, hasDtorResult)
draw string(0,70), "The 'String * 10' Type has a destructor (implicit or explicit): "& hasDtorResult
TypeHasDtorRun(stringptrType, hasDtorResult)
draw string(0,90), "The 'String Ptr' Type has a destructor (implicit or explicit): "& hasDtorResult
TypeHasDtorRun(Object, hasDtorResult)
draw string(0,110),"The 'Object' Type has a destructor (implicit or explicit): "& hasDtorResult
TypeHasDtorRun(UDT1, hasDtorResult)
draw string(0,130), "The 'UDT1' User-Type has destructor (implicit or explicit): "& hasDtorResult
TypeHasDtorRun(UDT2, hasDtorResult)
draw string(0,150), "The 'UDT2' User-Type has destructor (implicit or explicit): "& hasDtorResult
locate 12
print "Runs ",counter
loop
sleep