Page 1 of 1

Pass a Structured PointerList to a Procedure

Posted: Wed Feb 15, 2017 10:31 am
by Xanos
Hi all,
I wrote a procedure that sorts StructuredPointerLists() the same as the original SortStructuredList() procedure.

Code: Select all

Procedure SortStructuredPointerList(List *pointerlist(), options, offset, type)
However, the compiler only lets me pass *lists() that do not have any structure.
Since I do not use the structure elements anyway this is not needed inside the procedure, but for most of my StructuredPointerLists I use the structure elements (outside of the sorting procedure) and I do not want to remove the structure from the list out of lazyness ;)

TL;DR: How can I pass a PointerList with an arbitrary structure (.i, .s, .custom) to a procedure that only wants to work on the element pointers?
Everything is using pointers only anyway. Direct access using \ is just for simplicity but not required when working with pointers...

Example code:

Code: Select all

EnableExplicit

Structure myListStruct
  int.i
  str$
EndStructure
  
Procedure doStuff(List *pointerlist())
  ; here, some magic happens
EndProcedure


Define item1.myListStruct\int = Random(100)
Define item2.myListStruct\int = Random(100)
Define item3.myListStruct\int = Random(100)

Define NewList *pointerList.myListStruct()
AddElement(*pointerList())
*pointerList() = @item1
AddElement(*pointerList())
*pointerList() = @item2
AddElement(*pointerList())
*pointerList() = @item3

doStuff(*pointerList()) ; Throws: [COMPILER] The list doesn't match with the procedure parameter.
When passing a List$() to a function that expects a List.i(), this makes totally sense. But with pointerLists I don't see the reason.

Re: Pass a Structured PointerList to a Procedure

Posted: Wed Feb 15, 2017 10:38 am
by Bisonte

Code: Select all

Procedure doStuff(List *pointerlist.myListStruct())

Re: Pass a Structured PointerList to a Procedure

Posted: Wed Feb 15, 2017 10:40 am
by Xanos
The function should work on any pointerList, not bound to a specific structure. That is why I asked:
How can I pass a PointerList with an arbitrary structure (.i, .s, .custom) to a procedure

Re: Pass a Structured PointerList to a Procedure

Posted: Wed Feb 15, 2017 10:47 am
by Bisonte
ok. translation error :oops: