Pointer

2021-04-18
2021-04-19
  • codesystart - 2021-04-18

    Hello

    I have a Interface Method defined with following inputs.
    VAR_INPUT
    //receive buffer
    pbyRxBuffer : POINTER TO BYTE;
    //size of the receive buffer
    udiRxBufferSize : UDINT;
    END_VAR

    For eg: If i get udiRxBufferSize = 10, then i copy 10 bytes through pointers

    Now I am relying on udiRxBufferSize for the actual size of buffer. but what if i get a wrong input from user?? He says 10 bytes, but doesnt actually provide the required size.

    Can i somehow check the size of actual variable which is provided in pbyRxBuffer??

    Also, i have a query for adding pointers

    when I do pbyRxBuffer := pbyRxBuffer+1; codesys always incrents 1 pointer by 1 byte only.(irrespective of whether it is defined as POINTER TO BYTE or POINTER TO ULINT)

    is my observation correct??

    I was expecting that if the pointer is POINTER TO ULINT, it shoul increase by 1 ULINT

    Note : I cannot change the interface

     

    Last edit: codesystart 2021-04-18
  • i-campbell

    i-campbell - 2021-04-18
    1. Type safety of pointer.
      I do not know of a way to do that without changing the interface to, for example, REFERENCE TO ARRAY [*] OF BYTE;

    2. Incrementing POINTER TO ULINT.
      Pointers are always to a byte address. So as you said, puliVar + 1 would now be pointing to a ULINT which overlaps the old one.
      If you want to reference a ULINT which is 8bytes after your puliVar, you can use puliVar[1]. The online help for pointer probably explains it more clearly https://help.codesys.com/webapp/_cds_datatype_pointer;product=codesys;version=3.5.16.0

     

    Related

    Talk.ru: 1

  • codesystart - 2021-04-19

    Ok Thankyou for the info.

    I guess we cant really do type safety of pointers...

    The second part wont cause much issues. I think i can manage it in my code...

     

Log in to post a comment.