Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pointers Yet Again
#11
No idea, it isn't so simple to add, parser module just for variables is already ~800 lines long, 'cause all the ambiguities with BASIC vars, ugh.

There will be no way to use () for pointer indexing, for example, it will have to be [] -- i am thinking about making it an C array, so you could do like: myptr[dim2][dim1], no info about the array is needed, as n-dimensional C arrays are arrays of pointers of pointers and so on (in PB you have to do: myptr[dim1 of 4, dim2 of 2] for example, i don't like it.
Reply
#12
Ok. But in the mean while do you know how to modify the new code to include all kinds of pointer arrays (udt's for example). I guess it's based on simple pointer arithmetic.

Sample Code based on your example:

Code:
const MAXITEMS = 4

Type test
     strs As string ptr
End Type

Function MakePtrArr(elem As Long, bytes As Long) As Any Ptr
    MakePtrArr = Allocate(elem * bytes)
End Function

Sub PutPtrArr(arr As Any Ptr, item As Any Ptr, elem As Long, numelems As Long, bytes As Long)
    Dim temp as Any Ptr
    temp = arr
    temp = temp + (numelems * bytes)/elem
    *temp = *item
    arr = temp      
End Sub

Function GetPtrArr(arr As Any Ptr, elem As Long, numelems As Long, bytes As Long) As Any Ptr
    Dim temp as Any Ptr
    temp = arr
    temp = temp + (numelems * bytes)/elem
    GetPtrArr = temp
End Function

   Dim t1 As test
   dim p as string ptr

   Redim teststr(3) As String

   teststr(0) = "Zero"
   teststr(1) = "One"
   teststr(2) = "Two"
   teststr(3) = "Three"

   t1.strs = MakePtrArr(4, 64)

   ' Copy Data into string ptr
'   p = t1.strs
   For i = 0 To MAXITEMS-1
       PutPtrArr(t1.strs, @teststr(i), i, 4, 64)                '' can't do t1.strs[i] while there's no pointer indexing      
   Next

   Print "Works"    

   Erase teststr

   For i = 0 To MAXITEMS-1
       Print *GetPtrArr(t1.strs, i, 4, 64)                    '' same as above
   Next

   sleep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)