This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Building a realloc function?

Hey guys,

since realloc isn't ANSI C and for that not support by KEIL I tried to create my own realloc function.

But - as usual - I have some pointer trouble :-/ .

Here is my try for this memory reallocation function. But it doesn't compile because of the statement in the for loop:

void* Memrealloc(void* pvMem, uint32_t ulNewSize)
{
int i;
char *ptr; //Pointer for the new memory area

ptr = (char*)malloc(ulNewSize);  //Allocating the amount of requested memory

for (i=0; i<=ulNewSize;i++)
{
ptr[i]=(char*)pvMem[i];  //Copy the old content of the memory
}

free (pvMem);       //Deallocating the old memory

return (void*)ptr;   //Returning pointer to the new memory
}

Thats the error I get:
Source\OS_Custom.c(79): error: #852: expression must be a pointer to a complete object type

What is happening here? What do I have to do to fix it?

Parents Reply Children