4 automatic variables, 5 global variables, Automatic variables -26 – ElmoMC SimplIQ Software Manual User Manual
Page 55: Global variables -26
SimplIQ
Software Manual
4BThe
SimplIQ
User Programming Language
MAN-SIMSW (Ver. 1.4)
5-26
5.8.4
Automatic Variables
A variable declared within a function is automatic; it is generated when the function is
called and ceases to exist when the function exits. At the time of the function call, all of its
automatic variables are set to zero. When the function exits, the value of the automatic
variables is not saved.
Automatic variables cannot be vectors.
Example:
In the example of the statistic function in
section
, variable k is the automatic variable.
5.8.5
Global Variables
A function can reference a persistent variable, which, in this case, must be declared as
global inside the function and defined above the function definition. The global keyword is
obligatory; otherwise, the variable will be referenced as an automatic variable of the
function.
The dimension of a persistent variable is defined once in a program, during its definition,
and is the same for the global variable in all functions in which it is used. The legal way to
declare the dimension of a persistent variable within a function is to use empty brackets
after its name, or no brackets at all.
Examples:
In the example of the statistic function in
section
, variable vec[11] is the global variable.
It is defined above the function definition and is redeclared as global within the function
body.
float temp;
Declare the global vector variable.
int vec[10];
Declare the global vector variable.
…
function [float a]=func(int b)
Declare a function func.
float temp;
Declare temp as an automatic variable,
because the global keyword is absent.
… Function
body.
return
End
of
function.
…
function [float a]=func1(float temp)
Declare function func1. In this case, temp is
not a global variable, but rather an input
argument.
…
return
End
of
function.
…
function [float a]=func2(float b)
Declare function func2.
global float temp;
Redeclare global variable temp. In this
function, temp is the global variable.