Posted August 23, 200519 yr I'm guessing it's my copiler (Dev C++), but I'm just going to ask. Let's say I have a malloc function, which allocates the amount of memory I want, and then returns a pointer to the beginning of that block. However, when I try to malloc and return the adress to a char pointer, it gives me invalid conversion from void* to char*. I tried typecasting, but the ISO forbids it... any ideas?
August 23, 200519 yr 1) Dev-C++ is not a compiler, just a GUI. 2) Don't use malloc, use new and delete (In case of using C++, and NOT C that is). 3) The way to assign a void* to char* goes like this (This is a copy/paste of a memcpy, me and some other guys have made for an OS project): void* memcpy(void* dest, const void* src, size_t count) { void* ret = dest; unsigned char* csrc = (unsigned char*)src; unsigned char* cdest = (unsigned char*)dest; while (count--) { *cdest++ = *csrc++; } return cdest; } Note: This code is C, and I have not tried compiling it in C++.
August 23, 200519 yr Author 1) Dev-C++ is not a compiler, just a GUI. 2) Don't use malloc, use new and delete (In case of using C++, and NOT C that is). 3) The way to assign a void* to char* goes like this (This is a copy/paste of a memcpy, me and some other guys have made for an OS project): void* memcpy(void* dest, const void* src, size_t count) { void* ret = dest; unsigned char* csrc = (unsigned char*)src; unsigned char* cdest = (unsigned char*)dest; while (count--) { *cdest++ = *csrc++; } return cdest; } Note: This code is C, and I have not tried compiling it in C++. Thanks. Actually, it turns out I was being retarded and typecasting on the wrong side of the equation (what the hell was I thinking?). Anyway, it works now... so yeah. Thanks anyway. And it's not actually malloc that I'm using, it's GlobalAlloc (thought I assume they're pretty much the same thing). But whatever. Thanks for the help anyway.