Call by reference / value - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2) +--- Thread: Call by reference / value (/showthread.php?tid=2209) |
Call by reference / value - Kernelpanic - 11-27-2023 To once again take chances handing over arguments to procedures (and functions). A "Shared" is not necessary to access the address of a variable, as "Call by reference" is the standard access for procedures and functions in QuickBasic (QB64). "Shared" is only necessary if one want to make a variable accessible throughout the entire program. For "AlsWert einzahlung, (zinswert), jahre" (Line 31) only the interest value is passed as a value, since this value should be changed as a copy. Code: (Select All)
RE: Call by reference / value - mnrvovrfc - 11-27-2023 Just as long as everybody remembers each parameter is passed to a subprogram by reference. It means the value of a variable could be changed accidentally. BYVAL cannot be used away from DECLARE LIBRARY block, and therefore there is no easy way to do anything about it except to declare local variable copies that protect the incoming parameters. RE: Call by reference / value - SMcNeill - 11-28-2023 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. RE: Call by reference / value - TerryRitchie - 11-28-2023 (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.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. |