Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

'null' initialization of Array's with structures in them

marsim
2021-08-20
2021-08-21
  • marsim - 2021-08-20

    Hello,
    I am currently implementing a struct, let's call it Struct1, in which i have say multiple ints and an array[0..10] of Type Struct2, which can contain 1-10 Struct2's:

    TYPE Struct1:
    STRUCT
    id : usint;
    name : string;
    vars : ARRAY[0..10] of Struct2;
    END_STRUCT
    END_TYPE

    TYPE Struct2:
    STRUCT
    var_name : string;
    var_bit_start : USINT;
    var_bit_length : USINT;
    END_STRUCT
    END_TYPE

    The var array can contain 1-10 structs and i dont know beforehand how many, but I want to iterate over these struct2's later on.

    Now my question is, if i create a Struct1 'Object', how exactly do i set the structs in the var array? Is the Struct2 array already initialized with empty struct2's? When I iterate over them, can I somehow see if they are already 'set' to a value or still empty?

    Thanks in advance for any help!

     
    πŸ‘
    2
  • Ingo

    Ingo - 2021-08-21

    AFAIK the IEC61131 standard defines, that all variables are 0 initialized. It's more or less the other way around. You can define noinit if you want to avoid this initialization.

     

Log in to post a comment.