Thread: How do I move a pointer?

  1. #1
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003

    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.

    void *pData, *pPos;
    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:

    (uint)pPos= (uint)pData +iPosition;
    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 ?

  2. #2
    Registered User
    Join Date
    Jun 2003
    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:

    char *pData;

    and if it's an array of ints...

    int *pData;

    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)

  3. #3
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003

    In that case I got to use byte *pbData. I don't like chars.

    Seems to work
    Last edited by darksaidin; 08-17-2003 at 04:45 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  2. Tic Tac Toe Comp Move help
    By swgh in forum C++ Programming
    Replies: 5
    Last Post: 09-24-2008, 11:05 AM
  3. How to move file pointer using gotoxy
    By smooth in forum C Programming
    Replies: 3
    Last Post: 09-12-2008, 08:50 AM
  4. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  5. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 02:19 AM