Post Reply 
Global vs Local behaviour
05-03-2015, 08:33 PM
Post: #6
RE: Global vs Local behaviour
For my own piece of mind I wanted to verify how global user variables are passed into a program on the Prime, here is what I did, and what I found:

Here is the test program; please note that the input variable name (stx) is different from the global user variable name passed in (stg) on the command line below.

Code:

EXPORT stg;
EXPORT str(stx)
BEGIN   
  stg := stx;  
  return stg;
END;

The following is what I entered on the command line:

Code:

"test" (sto) stg                   “test”
stg                                   “test”    
str(stg)                            “test”
stg                                  “test”


I then changed the program to modify the value of the global user variable:

Code:

EXPORT stg;
EXPORT str(stx)
BEGIN   
  stg := stx * 10;  
  return stg;
END;

And entered the following on the command line:

Code:

10 (sto) stg                   10
stg                                   10    
str(stg)                            100
stg                                  100

As you can see the original value of the global user variable stg (10) is passed into the program via the input variable stx in the program. The value of the global user variable stg is then modified by the program and returned with the new value by the RETURN statement.

Summary:

Input variables are passed by value and not by reference.

You must use a different name in your program for the local input parameter variable than that of your global user variable used for RETURN.

You can pass in the same global user variable as that declared in your program, and then modify and return the new value in the same global user variable name.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Global vs Local behaviour - DrD - 05-02-2015, 03:24 PM
RE: Global vs Local behaviour - kharpster - 05-02-2015, 08:38 PM
RE: Global vs Local behaviour - DrD - 05-02-2015, 09:56 PM
RE: Global vs Local behaviour - kharpster - 05-02-2015, 10:29 PM
RE: Global vs Local behaviour - DrD - 05-03-2015, 02:18 AM
RE: Global vs Local behaviour - kharpster - 05-03-2015 08:33 PM
RE: Global vs Local behaviour - DrD - 05-04-2015, 11:34 AM
RE: Global vs Local behaviour - DrD - 05-04-2015, 01:47 PM
RE: Global vs Local behaviour - leprechaun - 05-04-2015, 05:47 PM



User(s) browsing this thread: 4 Guest(s)