Variable Length Array - Cannot mix variable and fixed length dimensions?

SLUCodesys
2025-05-23
2025-05-26
  • SLUCodesys - 2025-05-23

    Using Codesys 3.5.18.30
    I am trying to work with an array of variable length in one dimension, but known in the other dimension.
    For example, using an array that represents a list of items, each with an attribute profile.
    I do not know how many items will be in the list, but I know that every item has 5 attributes, like size, weight, etc.

    Codesys does not seem to be able to accept this.
    I have referenced Data Type: ARRAY OF documentation page, which is not explicit if variable & fixed length array dimensions can be mixed.
    In the VAR_IN_OUT scope, I initially tried
    MY_ARRAY : ARRAY [*, *] OF REAL;
    which was no problem, of course. I then modified it to
    MY_ARRAY : ARRAY [*, 1..5] OF REAL;
    which throws
    C0006: ', or ]' expected instead of '..'
    among consequent downstream errors.

    I then used the Auto Declare -> Array Wizard, which accepted (asterisk)-(asterisk) and 1-5 for 2-dimensional lower and upper bounds.
    It output:
    MY_ARRAY: ARRAY[*..*, 1..6] OF INT;
    which throws the same error stream.

    What's the deal here? Is this possible?

     

    Last edit: SLUCodesys 2025-05-23
  • andrax

    andrax - 2025-05-24

    Arrays with variable lengths are a bad idea.
    This makes your system unstable and can lead to crashes.
    Declare your array large enough to reserve enough memory

     
  • Dave_T - 2025-05-26

    VAR CONSTANT
    size : INT := 10;
    END_VAR

    My_Array : ARRAY[1..SIZE , 1..5] OF REAL;

     

Log in to post a comment.