Hi,
I'm trying to pass a pointer to a function, and then have the function allocate some memory for that pointer. Is this possible?
I tried the following code, but doesn't seem to work. Once I return from the function, the pointer seems to be void. The program crashes when I try to access it in main with memcpy() or some other function.
Code:int main() { unsigned char *ptr; int memSize; unsigned char temp[1024]; // 1024 is larger than memSize foo(ptr, &memSize); memcpy(temp, ptr, memSize); } void foo(unsigned char *ptr, int memSize) { *memSize = someotherfunction(); ptr = (unsigned char *)malloc(*memSize) }




Reply With Quote