Skip to main content

POU: CheckPointer

Monitoring function for pointers (CheckPointer)

Use this function to monitor the memory access of pointers in runtime mode.  As opposed to other monitoring functions, a standard suggestion does not exist for the implementation of CheckPointer. You must define an implementation according to your own requirements.

The CheckPointer function should check whether or not the passed pointer references a valid memory address, and whether or not the orientation of the referenced memory area matches the variable type to which the pointer refers. If both conditions are fulfilled, then the pointer is returned. If not, then the function should complete an appropriate error handling.

Caution

To get the feature for monitoring functions, do not edit the declaration part. However, you are permitted to add local variables.

Important

An implicit monitoring function call does not occur for THIS pointer and SUPER pointer.

Important

In compiler version 3.5.7.40 and higher, the CheckPointer also affects REFERENCE variables the same as pointer variables.

Example 538. Template

Declaration:

//  Automatically generated code: DO NOT EDIT
FUNCTION CheckPointer : POINTER TO BYTE
VAR_INPUT
        ptToTest : POINTER TO BYTE;
        iSize : DINT;
        iGran : DINT;
        bWrite: BOOL;
END_VAR

Implementation: (incomplete)

//  Not a standard implementation. Insert your code here.
CheckPointer := ptToTest;
. When the function is called, it receives the following input parameters:
  • ptToTest: Target address of the pointer

  • iSize: Size of the referenced variable; the data type of iSize must be compatible with INT and cover the dimensional scope of the variables

  • iGran: Granularity of the referenced size; this is the largest non-structured data type contained in the referenced variables; the data type of iGran must be compatible with INT

  • bWrite: Access type (TRUE = write access, FALSE = read access); the data type of bWrite has to be BOOL

When the result of the check is positive, the unchanged pointer is returned (ptToTest).