Program local variables issue
|
02-10-2020, 02:25 AM
Post: #1
|
|||
|
|||
Program local variables issue
In many HPPL programs I have seen declarations of variables placed outside of the bodies of any programs or functions of the module. Those variables were sometimes preceded by a keyword LOCAL, sometimes they were not. The variables were often initialized.
I am assuming that the goal of this structure was to create variables that had scope limited to the module (equivalent of a static global variable in c/c++). Personally, I try to avoid such style. I try to declare all variables as locals in the body of the program and pass them to the functions as arguments. If I happen to need a global variable, I export it. Recently I ran into problems with such a program I was trying to use. It could be ran only once. Every subsequent run was generating an error. I spent some time analyzing what's going on, and here is what I found. The following program demonstrating the issue: Code: LOCAL List:={}; Inside the program the values of initialized variables are displayed, then they are modified to state_2, displayed again, and, finally, modified again to state_3 before exiting the program. Please compile the program and run it. You will see the variable values displayed in order: state_1 and state_2, as it should be. Then run the program again (without recompiling!). You will see the variable values displayed in order: state_3 and state_2. Upon second run the variables were not initialized. More on, the supposedly local variables from the previous run somehow survived in the OS and were passed to the program upon subsequent run. It is my understanding that the variables, as locals, should be destroyed the very moment the program terminates. After the program returns control to the OS, the variables in question cannot be found in any variable catalog in the calculator menus, which seems to indicate they were not exported. Can anybody shed some light on this behavior? (Ran on G2 and simulator, f/w 2020 01 16.) Darius |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)