pTAL Reference Manual (G06.24+, H06.09+, J06.03+)
int k := i + j; ! k has sublocal scope and is visible only
! in subprocedure s.
end;
! k is not visible here. It is created and destroyed every
! time subprocedure s is called.
end;
! j is not visible here. It is created and destroyed every time
! procedure p is called.
! i is accessible here and exists as long as the program is
! running.
Variables that have different scopes can have the same name, but they are different variables.
Example 4 Global and Local Variable With the Same Name
int(32) i; ! This i is global
proc p;
begin
int i; ! This i is local to procedure p, different
! from global variable i, and makes access to
! global variable i impossible ("hides" it).
i := i + 1D; ! ERROR: local variable i is INT(16)
end;
For local and sublocal variables, the compiler generates code to evaluate and store an initialization
expression. For example, for the expression
int k := i * j;
if i, j, and k are local or sublocal variables, the compiler generates code to multiply i by j and
store the product in k.
For global variables, the compiler does not generate such initialization code. Initial values assigned
to global variables are determined by the linker.
Typed Integer Constants
A constant is a value you can store in a variable, declare as a LITERAL, or use as part of an
expression. Constants can be numbers or character strings. The following are examples of constants:
ExampleConstant Type
"abc"Character string
654Numeric
You can specify numeric constants in binary, octal, decimal, or hexadecimal base, depending on
the data type of the constant. The default number base in pTAL is decimal. The following are
example constants in each number base:
ExampleNumber Base
-654INT(16) Decimal
+654D or +654 D (% not allowed)INT(32) Decimal
654F or 654 F (% not allowed)FIXED Decimal
%B101111INT(16) Binary
%B101111D or %B101111%D or %B101111% DINT(32) Binary
%B101111F or %B101111%F or %B101111% FFIXED Binary
44 Language Elements