Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Call by reference / value
#4
(11-28-2023, 02:36 AM)SMcNeill Wrote: Thing to remember is that passing via reference only works IF variable types match.  For example, change the types from DOUBLE to _FLOAT in the program above.

Best practice, if one doesn't want values to pass by reference, is just to pass to temp variables.

SUB foo(tempX, tempY)
    x = tempX: y = tempY
    'Now use x/y with zero worry over changing your original variable values.
Yep, I explain this method in Lesson 6 of the tutorial here. The code that generates Figure 7 (variablepassing2.bas) is an example of Steve's method.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply


Messages In This Thread
Call by reference / value - by Kernelpanic - 11-27-2023, 07:54 PM
RE: Call by reference / value - by mnrvovrfc - 11-27-2023, 11:19 PM
RE: Call by reference / value - by SMcNeill - 11-28-2023, 02:36 AM
RE: Call by reference / value - by TerryRitchie - 11-28-2023, 03:41 AM



Users browsing this thread: 2 Guest(s)