How do I move a pointer?
I assume a pointer is not much different from an unsigned integer: it stores a value between and including 0 and 2^32-1. For a pointer, this equals the targets position in memory measured in bytes from the first byte in memory (0).
I have two pointers. One, pData, points to a valid location in memory with a lot of data. The second one, pPos is supposed to move within this chunk of data like a filepointer (like seek) does within a file.
To move pPos' targetaddress in memory, I wanted to cast it to an integer, add the number of bytes I want to move it and cast it back. So thats what I did:
void *pData, *pPos;
Unfortunatly this does not compile. Obviously the compiler "knows what I mean" but doesn't allow it. I assume it does this because there is a better way of doing this in C++. So how do I do that ? Can anybody help me ? :)
(uint)pPos= (uint)pData +iPosition;
Why not use a pointer to the actual data type, rather than a void pointer which could point to anything and make your program more difficult to understand?
Eg. If you "data area" is a char array, setup the pointer like this:
and if it's an array of ints...
Note: Incrementing a pointer by 1 in these cases will advance to the next element, not the next byte, so...
pData++ where pData is defined as char *pData would increment the pointer by sizeof(char)
In that case I got to use byte *pbData. I don't like chars.
Seems to work :)