Seems to work in gas!
1)
Put as initializer 'New UDT' inside the UDT declaration is very daring.
At least put that declaration after the data fields!
Try with:
Code: Select all
Type points
Private:
As Long x,y 'a position
as long EndOfPointer
static as string message 'a message
Public:
Declare Function set(As Ulong=0,As Byte=0,byref as points ptr=new points) Byref As points Ptr 'setter/getter
Declare Function box(As long,As long,As long, As long) As points Ptr
declare operator cast() as string 'print
End Type
Compile in gcc:
- seems to work in gcc 32-bit,
- does not work in gcc 64-bit.
2)
Apart from that, your code in 'points.set()' is very unsafe.
'New' without 'Delete' => memory leak in the loop => used memory increasing indefinitely.
3)
With:
Code: Select all
Function points.set(c As Ulong,FillFlag As Byte,byref pt as points ptr) Byref As points Ptr
Static As points Ptr p',pt
' pt=new points
Function= p 'get
If p Then 'set
For n as long =1 To EndOfPointer
If n=1 Then Pset(p[n].x,p[n].y),c Else line -(p[n].x,p[n].y),c
if n= EndOfPointer then line (p[n].x,p[n].y)- (p[1].x,p[1].y),c ' close
Next
pt->x=p[0].x 'retrieve and return the centroid
pt->y=p[0].y
function=pt 'return the centroid
If FillFlag Then Paint(p[0].x,p[0].y),c,c
circle(pt->x,pt->y),3,,,,,f
End If
' delete p
' p=0
End Function
works also in gcc 64bits, but always memory leaks.