memory block copy error


Why does visual studio refuse to execute this function? I thought this was how memory blocks were copied?

Additional notes: I'm working on the gba and I have to copy a memoryblock in bytes in order to write to the memory slot(game saves)

void * memcpy(void * dst, void const * src, size_t len)
{
char * pDst = (char *) dst;
char const * pSrc = (char const *) src;
while (len--)
{
///////////////////////////////////////////////
//error section here
*pDst++ = *pSrc++;
///////////////////////////////////////////
}
return (dst);
}
Define "refuse to execute".

This simple test runs fine for me (Visual Studio 2005):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>

void * memcpy(void * dst, void const * src, size_t len)
{
    char * pDst = (char *) dst;
    char const * pSrc = (char const *) src;

    while (len--)
    {
        ///////////////////////////////////////////////
        //error section here
        *pDst++ = *pSrc++;
        ///////////////////////////////////////////
    }

    return (dst);
}

int main()
{
    char hello[] = "hello";
    char hi[] = "hi";

    memcpy(hello, hi, 2);

    std::cout << hello << std::endl;

    return 0;
}


Perhaps it's a problem with the calling code.
closed account (zb0S216C)
It's C++, not C (determined by the use of std). Use the new casting operators.

 
char *pDst(static_cast<char *>(dst));


Wazzak
Last edited on
Topic archived. No new replies allowed.