2.3.15. - Variables
A variable is brought into existence simply by using it. Variables assigned values at the top level (outside of any curly-bracketed statement block) are automatically made global. Otherwise, unless explicitly given global attributes, the scope of a variable lies only within the statement or statement block in which it occurs.
The possible attributes of a variable are as follows:
Local | A symbol with scope only in the statement block in which it appears. |
Global | A symbol with scope that carries across separate statement blocks. All built-in symbols are global. |
Built-in | A symbol that is compiled into spec and that cannot be removed. |
Constant | A global symbol that cannot have its value altered by ordinary assignment. Such a symbol can only be changed using the constant command. |
Immutable | Certain built-in symbols and motor and counter mnemonics from the hardware config file, which cannot have their values altered. |
Variables can have string, number or array type and may have both string and number types simultaneously. The
print
command always prints the string representation of a variable.
The formatted printing commands
printf
, fprintf
and
sprintf
print the string or number value, depending on the format specification.
If the string value cannot be interpreted as a
number, its number value is zero.
All number values are maintained as double-precision
floating-point quantities.
Uninitialized variables have a number value of zero and a string value of
""
(the null string).
Although associative
array indices are internally derived from the string value
of the index expression,
if the index is an uninitialized variable, its value for
purposes of indexing the array is the string
"0"
. Functions such as
input()
,
getline()
,
gpib_get()
and
ser_get()
return string values that possibly represent numbers.
When the string is used in a number context, automatic string to number
conversion takes place.
The conversion rules require that there are
no extraneous characters in the string.
An initial
0x
or
0X
introduces a hexadecimal integer.
An initial
0
introduces an octal constant, unless there is a decimal point or an
e
or
E
exponential string, in which case the entire string is interpreted as
a decimal number, leading zero notwithstanding.
- 2.3.15.1. - Built-In Variables