Results 1 to 3 of 3

Thread: Function_ReturnValue/ Function_ResultPtr

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171

    Post Function_ReturnValue/ Function_ResultPtr

    we all know the case when a function has to return some value

    The memory for that value is already allocated somewhere when we write

    Function myFun() As <Result>
    
    ' where <Result> is the type of the functions return-value
    
    ' data as <Result> gets assigned within the function alike:
    
    Function = 1
    ' but how can it be used within the function?
    
    
    if Function = 1 Then
      ' this will work only because "Function" is followed by an equal-sign here
    Endif
    
    Function = Function + 1 ' this won't work... :(
    
    End Function
    
    it's not possible to request/use the current functions return-value in other cases, so we have to store it to some other local variable for further calculations, which is a waste of time & memory since the value is already present and stored somewhere.

    If we knew the current functions return-values memory-position ("Function_ResultPtr") we could use a layover and alter single subelements if the function-result-type where an udt or if we had a built-in Function that tells us the current Function_ReturnValue then we could use it for further calculations without having to create an additional local variable...

    Function myFun1() As t_XY
    
      Local RetVal As t_XY At Function_ResultPtr 
      
      RetVal.X = 1
      RetVal.Y = 234
    
    End Function
    
    Function myFun2() As String
    
       Function = "Hello "
       Function = Function_ReturnValue & "world!"
    
    End Function
    
    Function myFun3() As Long
    
      Poke(Long, Function_ResultPtr, 123)
      Function = Function_ReturnValue * 456
      
    End Function
    
    Last edited by ReneMiner; 17-09-2015 at 16:39.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10
    Have you thought to some parameters passed BYREF ?
    Passing BYREF let you just have any function cascading all referencing the same variable/memory area.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    yes i thought about it.

    The user then still has to create local data sometimes, especially if udt-subelements shall be passed ByRef he needs at least a local layover.
    Also Byref returned Function-results are not instantly useable on the same line of code, while a function-return-value can be inserted via the call as a parameter within another call - else one would have to store the first result in a local variable temporary.

    And this is mostly the intention behind this idea - have plain code and avoid to allocate additional memory if possible, to speed things up.
    I think there are missing some Forum-sections as beta-testing and support

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •