Array questions

  • EmbeddedSalsa

    EmbeddedSalsa - 2018-02-20

    Dear all, it possible to declare an array, with a size taken from initializer.
    In C it is:
    int a[]={1,2,3}

    How I do the same in codesys?
    Please note, I DON'T request run-time dynamic array. I only request to don't declare a size abut take it from amount of initializers, like in C.

    1. How array are passed in function blocks?

    Var input
    invar array [0..5] of int;
    end var

    What is passed only the "reference" or the copy of the whole array on the stack. If so, how do I only pass array by reference? I want to read from array inside of the block, but don't want to write something back.

    Note: Pointers are not allowed in my company.
    Thanks a lot!

  • Anonymous - 2018-02-22

    Originally created by: scott_cunningham

    An answer to your second question:

    There are two solutions for passing an array reference without passing the whole array while not using pointers:

       History : REFERENCE TO ARRAY[0..99] OF DWORD;
  • EmbeddedSalsa

    EmbeddedSalsa - 2018-02-23

    Thanks a lot, Scott!
    I would like ask Codesys (if they read) to implement Const References for that and also implement my 1. point in ST.

  • maniek765

    maniek765 - 2018-04-03

    EmbeddedSalsa hat geschrieben:
    Note: Pointers are not allowed in my company.



Log in to post a comment.