Union - Array and String❓

2021-02-05
2021-02-05
  • andras-mozes

    andras-mozes - 2021-02-05

    Hello,

    I have data in format of ARRAY[0..124] OF WORD.

    TYPE DUTtest :
    UNION
        aData : ARRAY[0..124] OF WORD;
        strData : STRING(125*2);
    END_UNION
    END_TYPE
    

    It works - without using any for loop -, but I would like to understand the details that is what STRING(125*2) does?

    Thanks in advance.

     
  • dFx

    dFx - 2021-02-05

    Feels like some nerdish code writing style.
    String is no more than a byte array. With this in mind, to get the same length than the word array, you need to double the word array length.
    You could define string(250) and it would also work.

    Actually as 125x2 is a constant, it is probable that the compiler will just compile the same.

     
    πŸ‘
    1

    Last edit: dFx 2021-02-05

Log in to post a comment.