Function returns

Blitz3D Forums/Blitz3D Beginners Area/Function returns

David Scifa(Posted 2003) [#1]
Is it possible to return more than one variables from function?


jhocking(Posted 2003) [#2]
Not with Return, but there are a number of ways to affect more than one variable/stored value from inside a function. One obvious way is to use global variables. Or use arrays (which are always global.) Or use types, etc.


Gabriel(Posted 2003) [#3]
I use types if possible. They make life so much easier. If you've got a lot more variables you want to return, then maybe look into banks.


Richard Betson(Posted 2003) [#4]
Couldn’t you return an integer as a variable and then be able to return 4 bytes of variables?

L8r,


Anthony Flack(Posted 2003) [#5]
Damned annoying having to pack, send, and then unpack them bits all the time tho...


Anthony Flack(Posted 2003) [#6]
Damned annoying having a double post...


Oldefoxx(Posted 2003) [#7]
Function return values can be returned in various ways - if you wrote the function. For instance. you normally find the single value returned by built-in functions to appear in the AX or EAX register. depending upon if it is an integer or a long. Paramters passed into functions or subs are placed on the stack and accessed from there from within the procedure, and stripped off the stack automatically when the procedure is exited.

The mechanism for calling the procedure and causing the return are part of the compiler operations. You could technically test to see if the values in the various registers can be passed sucessfully into a procedure, either function or sub, and if values can be returned in like manner. If so, you potentially could have several
registers available to return values with - AX, BX, CX, DX,
SI, DI, EAX, EBX, ECX, and EDX are the most obvious possibilities. However, these are not capabilities of a compiler by direct means. You have to resort to assembler to make use of such techniques.

For most people, it just seems to make more sence to try to pass values in ways that work at the compiler level. This protects your code from potential changes in the mechanisms that are uaed as part of the compiler. This means you can pass values in arrays or tables, pack them into extended strings, and pass them as elements in a dimentioned TYPE structure. Or use Globals, as already mentioned.