L-force | plc designer – Lenze PLC Designer PLC Designer (R3-1) User Manual

Page 1042

Advertising
background image

L-force | PLC Designer

Programming Reference

1040

DMS 4.1 EN 03/2011 TD29

Index access to pointers
As extension to the IEC 61131-3 standard, index access "[]" to variables of type
POINTER, STRING and WSTRING is allowed.
• pint[i] will return the base data type
• Index access on pointers is arithmetic: If the index access is used on a variable of

type pointer, the offset will be calculated by: pint[i] = (pint + i * SIZEOF(base type))^.
The index access also performs an implicit dereferencation on the pointer. The
result type is the base type of the pointer. Note that pint[7] != (pint + 7)^!

• If the index access is used on a variable of type STRING, the result is the character

at offset index-expr. The result is of type BYTE. str[i] will return the i-th character of
the string as a SINT (ASCII).

• If the index access is used on a variable of type WSTRING the result is the character

at offset index-expr. The result is of type WORD. wstr[i] will return the i-th
character of the string as INT (Unicode).

Note: There is also the possibility of using References, which in contrast to a pointer
directly affect a value.


CheckPointer function
For checking pointer access during runtime you might use the implicitly available
check function "CheckPointer" being called before each access on the address of a
pointer. Therefore add the object "POUs for implicit checks" to the application using
the Add Object dialog. Mark the checkbox related to the type CheckPointer, choose an
implementation language and confirm your settings with Open, whereon the check
function will be opened in the editor corresponding to the implementation language
selected. Independently of that choice the declaration part is preset and may not be
modified except for adding further local variables! However, in contrast to other check
functions, there is no default implementation of CheckPointer available, the
implementation is left to the user!
Function CheckPointer should check whether the address the pointer refers to is within
the valid memory range. In addition it should be taken care of that the alignment of
the referenced memory area fits to the data type of the variable the pointer points to.
If both conditions are fulfilled, CheckPointer should return the unchanged input
pointer. A proper handling of detected error cases is left to the user.

Advertising