CODESYS permits the index access []
to variables of type POINTER TO
, as well as to the data types STRING
or WSTRING
.
The data, which the pointer points to, can also be accessed by appending the bracket
operator []
to the pointer identifier(for example, piData[i]
). The base data type of the pointer determines the data type and the size of the
indexed component. In this case, the index access to the pointer is done arithmetically
by adding the index dependent offset i * SIZEOF(<base type>)
to the address of the pointer. The pointer is dereferenced implicitly at the same
time.
Calculation:
piData[i] := (piData + i * SIZEOF(INT))^;
That is not not:
piData[i] != (piData + i)^;
Index access
When you use the index access with a variable of the type STRING
, you get the character at the offset of the index expression. The result is of type
BYTE
. For example, sData[i]
returns the i-th character of the string sData
as SINT
(ASCII).
Index access
When you use the index access with a variable of the type WSTRING
, you get the character at the offset of the index expression. The result is of type
WORD
. For example, wsData[i]
returns the i-th character of the string as INT
(Unicode).