I have an array of x bytes. I want to process this data somewhere else in my program so I want to use pointers. I want to be able to increment the pointer address in an easy way. I know have the following code:
receivedData : ARRAY [0..MAX_RECEIVE_TCP_SERVER] OF BYTE;
processCommand( ADR(receivedData[6]) );
FUNCTION processCommand : BOOL
VAR_INPUT
dataPtr : POINTER TO BYTE;
END_VAR
VAR
channel: BYTE;
value: UINT;
state: BYTE;
END_VAR
channel := dataPtr^;
dataPtr := dataPtr + 1;
value := dataPtr^;
dataPtr := dataPtr + 1;
value := value + (dataPtr^ * 256);
dataPtr := dataPtr + 1;
state := dataPtr^;
dummyFunction(channel, value, state);
Is there an easier way to increment the pointer address? I would prefer to have something like this, but I don't know if this is possible:
dummyFunction(dataPtr[0]^, dataPtr[1]^ + dataPtr[2]^ *256 , dataPtr[3]^);
Hello all,
I have an array of x bytes. I want to process this data somewhere else in my program so I want to use pointers. I want to be able to increment the pointer address in an easy way. I know have the following code:
receivedData : ARRAY [0..MAX_RECEIVE_TCP_SERVER] OF BYTE;
processCommand( ADR(receivedData[6]) );
FUNCTION processCommand : BOOL
VAR_INPUT
dataPtr : POINTER TO BYTE;
END_VAR
VAR
channel: BYTE;
value: UINT;
state: BYTE;
END_VAR
channel := dataPtr^;
dataPtr := dataPtr + 1;
value := dataPtr^;
dataPtr := dataPtr + 1;
value := value + (dataPtr^ * 256);
dataPtr := dataPtr + 1;
state := dataPtr^;
dummyFunction(channel, value, state);
Is there an easier way to increment the pointer address? I would prefer to have something like this, but I don't know if this is possible:
dummyFunction(dataPtr[0]^, dataPtr[1]^ + dataPtr[2]^ *256 , dataPtr[3]^);
Related
Talk.ru: 1
Talk.ru: 2
Talk.ru: 3
Originally created by: scott_cunningham
Instead of defining a pointer to byte, define your pointer as:
Then you can access your data with array indexing like you wish.
Thanks for your reply. Unfortunately, this is not possible (error 4110, '[<index>]</index>' needs array variable).
Other solutions, or is my implementation wrong: dummyFunction(dataPtr[0]^, dataPtr[1]^ + dataPtr[2]^ *256 , dataPtr[3]^);
Related
Talk.ru: 1
Talk.ru: 2
Talk.ru: 3
Originally created by: scott_cunningham
I am not by my computer, but I believe you need to dereference before index: dataPtr^[1].
Related
Talk.ru: 1
Works! Unbelievable I didn't try that... Thanks very much!
Related
Talk.ru: 1
Originally created by: scott_cunningham
If you get tired of dereferencing your pointer, you can use REFERENCE TO instead of POINTER TO. Check the help for more info.