Pass a Structured PointerList to a Procedure

Just starting out? Need help? Post your questions and find answers here.
User avatar
Xanos
User
User
Posts: 45
Joined: Sat Feb 28, 2015 1:20 pm

Pass a Structured PointerList to a Procedure

Post 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.
Last edited by Xanos on Wed Feb 15, 2017 10:39 am, edited 1 time in total.
Programming on Windows 10 Pro / Windows 7 Enterprise / Linux Mint 19 / Manjaro Linux with PB 5, Python 3 and Go
User avatar
Bisonte
Addict
Addict
Posts: 1313
Joined: Tue Oct 09, 2007 2:15 am

Re: Pass a Structured PointerList to a Procedure

Post by Bisonte »

Code: Select all

Procedure doStuff(List *pointerlist.myListStruct())
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
User avatar
Xanos
User
User
Posts: 45
Joined: Sat Feb 28, 2015 1:20 pm

Re: Pass a Structured PointerList to a Procedure

Post 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
Programming on Windows 10 Pro / Windows 7 Enterprise / Linux Mint 19 / Manjaro Linux with PB 5, Python 3 and Go
User avatar
Bisonte
Addict
Addict
Posts: 1313
Joined: Tue Oct 09, 2007 2:15 am

Re: Pass a Structured PointerList to a Procedure

Post by Bisonte »

ok. translation error :oops:
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
Post Reply