Sorry if this suggest was post in the past, but i don't find.
Any var-type return for Functions
- Psychophanta
- Always Here

- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Any var-type return for Functions
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.
Sorry if this suggest was post in the past, but i don't find.
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
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.
but this is rather unusual, and only possible for structures that cover maximum 64bit.
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 )oh... and have a nice day.
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Dräc wrote:Oh! I was’nt aware that you are on the PB development team, 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.
oh... and have a nice day.
