GLBasic forum

Main forum => Bug Reports => Topic started by: Moebius on 2011-Sep-17

Title: SORTARRAY with types and custom functions. [nvm - no bug in GLB]
Post by: Moebius on 2011-Sep-17
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:
Quote
In 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
Title: Re: SORTARRAY with types and custom functions.
Post by: Qube on 2011-Sep-17
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
Title: Re: SORTARRAY with types and custom functions.
Post by: MrTAToad on 2011-Sep-17
Byref isn't used when passing structures.
Title: Re: SORTARRAY with types and custom functions.
Post by: Moebius on 2011-Sep-17
Ahhh - knew I had something wrong.  Thanks!
Title: Re: SORTARRAY with types and custom functions. [nvm - no bug in GLB]
Post by: Kitty Hello on 2011-Sep-19
and types are always passed byref.