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
  • I said memset(), memcmp() and others.

    You are right. I guess I like assuming to much random stuff... :-)

    I think you should develop some understanding of the way your program is supposed to work.

    You are right, again. I will do that. I thought, that it would be a smart approach to first get all suggested requirements done, but I should really do some basic use of those functions first to see, what I actually need.

    I'll be back :)

Reply
  • I said memset(), memcmp() and others.

    You are right. I guess I like assuming to much random stuff... :-)

    I think you should develop some understanding of the way your program is supposed to work.

    You are right, again. I will do that. I thought, that it would be a smart approach to first get all suggested requirements done, but I should really do some basic use of those functions first to see, what I actually need.

    I'll be back :)

Children
No data