Page 1 of 1
Any var-type return for Functions
Posted: Sat Dec 18, 2004 9:59 am
by Psychophanta
Currently, procedures can return only PB internal native variable types, but it is more and more necessary to allow to return any variable type.
Sorry if this suggest was post in the past, but i don't find.

Posted: Wed Sep 12, 2007 8:49 am
by Dräc
[refresh

]
Is using structure has ProcedureReturn planned for an immediate future of the PB version? (and available for Interface also...)
Posted: Wed Sep 12, 2007 1:19 pm
by Kaeru Gaman
no.
Structures are always passed byRef.
that means you pass the pointer of a structure to be filled to the Procedure.
the Return Value can also be a pointer to a structure.
the Return Value of a Procedure is at max a Quad.
sure you can put this Quad into a StructureUnion.
Code: Select all
Structure DoubleCoord
C1.COORD
C2.COORD
EndStructure
Structure Passer
StructureUnion
StrP.DoubleCoord
QuaP.q
EndStructureUnion
EndStructure
Procedure.q GetCoords( X.w, Y.w )
Protected OutCoords.Passer ; define an internal Passer
OutCoords\StrP\C1\x = X + 100 ; fill the structured Part
OutCoords\StrP\C1\y = Y - 100
OutCoords\StrP\C2\x = X - 100
OutCoords\StrP\C2\y = Y + 100
ProcedureReturn OutCoords\QuaP ; return the quad Part
EndProcedure
Define TestCoords.Passer
TestCoords\QuaP = GetCoords( 200, 500 ) ; fetch a quad
Debug "C1\x = " + Str( TestCoords\StrP\C1\x ) ; debug the structured content
Debug "C1\y = " + Str( TestCoords\StrP\C1\y )
Debug "C2\x = " + Str( TestCoords\StrP\C2\x )
Debug "C2\y = " + Str( TestCoords\StrP\C2\y )
but this is rather unusual, and only possible for structures that cover maximum 64bit.
Posted: Wed Sep 12, 2007 2:52 pm
by Dräc
Posted: Wed Sep 12, 2007 3:03 pm
by netmaestro
Note though that if you want to ProcedureReturn a pointer to a structure and have all members of the structure available to the caller you must use AllocateMemory or a persistent scope like global or the memory is freed on exit.
Posted: Wed Sep 12, 2007 3:15 pm
by Kaeru Gaman
..no need to be on the team to answer this, because we just had a discussion about this lately,
and Freak himself stated that it is not at all planned to change the returning from how it is now.
the ReturnValue is in EAX for Long or smaller, for Quad or Double there is one additional Register used.
Freak said, they are not thinking about changing this way.
Posted: Wed Sep 12, 2007 3:17 pm
by Dräc

Ok! Thx Kaeru Gaman!