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

work with pointer

Paul
2007-12-03
2007-12-06
  • Paul - 2007-12-03

    I have array on structure target (x: byte, y : byte).

    var1 : array [1..30] of target;

    actual_var : pointer to target;


    value := actual_var^[5].x; ( didn't work )

    actual_var := actual_var + ( sizeof(target) * 5); ( didn't work )

    Where is problem?

    Thanks Paul

     

    Related

    Talk.ru: 5

  • Ralph Holz - 2007-12-03

    Hi Paul!

    Zitat:
    value := actual_var^[5].x; ( didn't work )

    Your Pointer is no array of something so you cant use indexes

    Zitat:
    actual_var := actual_var + ( sizeof(target) * 5); ( didn't work )

    Only sizeof(Variable) not Sizeof(Datatype) is possible.

    See the solutions below:

    VAR
    Β  Β var1 : ARRAY [1..30] OF target;
    Β  Β actual_var : POINTER TO ARRAY [1..30] OF target;
    Β  Β actual_var2: POINTER TO target;
    Β  Β value: BYTE;
    Β  Β value2: BYTE;
    END_VAR
    actual_var:= ADR(var1);
    value := actual_var^[5].x; (* works *)
    actual_var2:= ADR(var1);
    actual_var2 := actual_var2 + SIZEOF(actual_var2^) * DWORD#4; (* works *)
    value2:= actual_var2^.x;
    
     
  • RobiHerb - 2007-12-06

    Ist there any information about pointer arithmetic in st?

    Try and error is a bad solution for me.

     

Log in to post a comment.