SORTARRAY with types and custom functions. [nvm - no bug in GLB]

Previous topic - Next topic

Moebius

I'm having a slight problem with using custom functions with SORTARRAY.  The example (sorting primitive types) works, but not types are used.

This is the error:
QuoteIn file included from C:\Users\James\AppData\Local\Temp\glbasic\gpc_tempg.cpp:2:
C:\Users\James\AppData\Local\Temp\glbasic\gpc_temp.h:8: error: `Anything' was not declared in this scope
C:\Users\James\AppData\Local\Temp\glbasic\gpc_temp.h:8: error: `Anything' was not declared in this scope
C:\Users\James\AppData\Local\Temp\glbasic\gpc_temp.h:8: error: initializer expression list treated as compound expression

As gpc_temp.h is included in the different source files, this error is repeated a few times, but its complaining about the line of 'gpc_temp.h' that declares the sort function:
Code (glbasic) Select
DGInt SortFunc(Anything A, Anything B);


Demo snippet:
Code (glbasic) Select
TYPE MyType
var%
ENDTYPE

LOCAL Array[] AS MyType

SORTARRAY Array[], ADDRESSOF(SortFunc)


FUNCTION SortFunc:  BYREF A AS MyType, BYREF B AS MyType

IF A.var > B.var THEN RETURN 1
IF A.var < B.var THEN RETURN -1
RETURN 0

ENDFUNCTION
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

Qube

Have you tried (see below) - That's all I do and have no problems with compilation.

Code (glbasic) Select

FUNCTION SortFunc: A AS MyType, B AS MyType

IF A.var > B.var THEN RETURN 1
IF A.var < B.var THEN RETURN -1
RETURN 0

ENDFUNCTION

MrTAToad

Byref isn't used when passing structures.

Moebius

Ahhh - knew I had something wrong.  Thanks!
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

Kitty Hello