I'm very confused about void pointers and this notation here below. I do understand that when you have a void pointer you eventually cast it to some kind of type int, double. What I don't understand is what is happening here : copySize = *(size_t *)((char *)oldptr - SIZE_T_SIZE);
copySize is of type size_t and then we make it equal to oldptr casted to a char?
here is the whole code snipped. I would be very graceful for some "pointers" here ;)
void *mm_realloc(void *ptr, size_t size)
{
void *oldptr = ptr;
void *newptr;
size_t copySize;
newptr = mm_malloc(size);
if (newptr == NULL)
return NULL;
copySize = *(size_t *)((char *)oldptr - SIZE_T_SIZE);
if (size < copySize)
copySize = size;
memcpy(newptr, oldptr, copySize);
mm_free(oldptr);
return newptr;
}