Author Topic: SORTARRAY with types and custom functions. [nvm - no bug in GLB]  (Read 1710 times)

Offline Moebius

  • Dr. Type
  • ****
  • Posts: 315
    • View Profile
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
« Last Edit: 2011-Sep-17 by Serpent »
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

Offline Qube

  • Mr. Polyvector
  • ***
  • Posts: 157
    • View Profile
Re: SORTARRAY with types and custom functions.
« Reply #1 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
 

MrTAToad

  • Guest
Re: SORTARRAY with types and custom functions.
« Reply #2 on: 2011-Sep-17 »
Byref isn't used when passing structures.

Offline Moebius

  • Dr. Type
  • ****
  • Posts: 315
    • View Profile
Re: SORTARRAY with types and custom functions.
« Reply #3 on: 2011-Sep-17 »
Ahhh - knew I had something wrong.  Thanks!
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10720
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
and types are always passed byref.