I'm trying to assign two initialized arrays evenNumbers and oddNumbers to an array of arrays integers:
PROGRAM ArrayInit
VAR
evenNumbers : ARRAY[1..3] OF INT := [2, 4, 6];
oddNumbers: ARRAY[1..3] OF INT := [1, 3, 5];
integers : ARRAY[1..2] OF ARRAY[1..3] OF INT := [evenNumbers, oddNumbers];
END_VAR
This code gives me a compiler error
Array initialisation expected
Of course I can directly initialize integers with the numbers that I want like so:
PROGRAM ArrayInit
VAR
integers: ARRAY[1..2] OF ARRAY[1..3] OF INT := [
[2, 4, 6], [1, 3, 5]
];
END_VAR
or like Sergey mentioned
PROGRAM ArrayInit
VAR
integers: ARRAY[1..2, 1..3] OF INT := [
2, 4, 6, 1, 3, 5
];
END_VAR
However, if the original arrays are very big and/or I want to document what these different arrays are, a descriptive name would be nice. I.e. integers : ARRAY[1..2] OF ARRAY[1..3] OF INT := [evenNumbers, oddNumbers]; nicely shows that the integers has two lists, one with even and one with odd numbers.
I've also tried to initialize integers as integers: ARRAY[1..2] OF ARRAY[1..3] OF INT := [[evenNumbers], [oddNumbers]];, but this gives me the compiler error:
Cannot convert type 'ARRAY [1..3] OF INT' to type 'INT'
Now I wonder if it even possible? If so, does anyone know how I can do it?


