fxm wrote:The passed function pointer must be of type:
FUNCTION CDECL(AS ANY PTR, AS ANY PTR) AS LONG
To elaborate on fxm's statement, specifically, in the case of qsort.bas, because the prototype for the qsort function contained in crt/stdlib.bi is
Code: Select all
Declare Sub qsort (ByVal As Any Ptr, ByVal As size_t, ByVal As size_t, ByVal As Function(ByVal As Any Ptr, ByVal As Any Ptr) As Long)
the QCompare function prototype must be declared as
Code: Select all
Declare Function QCompare cdecl (ByVal e1 As Any Ptr, ByVal e2 As Any Ptr) As Long
and the QCompare function defined as
Code: Select all
Function QCompare cdecl (ByVal e1 As Any Ptr, ByVal e2 As Any Ptr) As Long
The QSort function is then called by passing the address of the callback function.
Code: Select all
#include "crt/stdlib.bi"
qsort @myArray(0), 10, SizeOf(Integer), @QCompare
The above code snippets are taken from the FreeBASIC Documentation "The Pointer Data Type" section.