global
keyword, followed by the variable’s type and name. For example:
op
is assigned the addition operator _+_
. The program then verifies the associativity of addition using three sample integers: 2, 3, and 9.
Under the hood, global variables in FunC are stored in the c7
control register of the TVM, with a maximum limit of 31 variables.
In FunC, you can omit the type of global variable.
In this case, the compiler determines the type based on how the variable is used.
For example, you can rewrite the previous program like this:
global
keyword.
The following examples are equivalent:
int C = 3;
is not declaring a new local variable
but instead assigning value 3
to the global variable C
.
This behavior is explained in more detail in the section on statements.