pTAL Reference Manual (G06.24+, H06.09+, J06.03+)
Example 49 Declaring and Initializing a Read-Only Array
STRING prompt = 'P' := ["Enter Character: ", 0];
INT error = 'P' := ["INCORRECT INPUT"];
Using Constant Lists in Array Declarations
pTAL requirements for array declarations are:
• If an array declaration includes an initialization string, the size of a constant list must be less
than or equal to the size of the array. If the constant list is larger than the array, an error
occurs.
• If the alignment of the elements of the initialization string under SHARED2 rules and SHARED8
rules is different, you must specify a FIELDALIGN clause in the initialization string.
The number of bits in a constant list that you assign to a read-write array must be the same as the
number of bits in the array. The number of bits in a constant list that you assign to a read-only
array must be the less than or equal to the number of bits in the array.
Topics:
• Read-Only Arrays (page 113)
• Nonstring Arrays (page 113)
Read-Only Arrays
The number of bits in the initialization string must equal the number of bits in the read-only array.
If the read-only-array declaration does not specify array bounds, the number of bits in the
initialization string must be an integral multiple of the number of bits in the array’s base type.
Example 50 Declaring Read-Only Arrays With Constant Lists
INT p = 'P' := "abcd"; ! OK
INT q[0:3] = 'P' := "abcdabcd"; ! OK
STRING r = 'P' := "abcd"; ! OK
STRING s[0:3] = 'P' := "abcd"; ! OK
STRING t = 'P' := [1,2,3]; ! OK
STRING u[0:3] = 'P' := [1,2,3]; ! ERROR: Initialization size
! (24 bits) must equal the
! array's size (32 bits)
STRING v = 'P' := [1,2,3,4]; ! OK
STRING w[0:3] = 'P' := [1,2,3,4]; ! OK
INT x = 'P' := "abc"; ! ERROR: Initialization size
! must be an integral
! multiple of array's base
! type size
Nonstring Arrays
You can specify an initialization string when you declare an array:
INT .a[0:3] := [0,1,2,3];
The length of the initialization string must be less than or equal to the length of the array.
Example 51 Declaring Nonstring Arrays With Constant Lists
INT .a[0:3] := [0,1,2]; ! OK: Init string is shorter than array
INT .a[0:3] := [0,1,2,3]; ! OK: Init string is right length
INT .a[0:3] := [0,1,2,3,4]; ! ERROR: Init string is too long
INT .a[0:3] := [%H1234567812345678%F]; !OK: Init string is right length
Declaring Arrays 113