I'm not sure the proper way to handle the casting of types when using malloc
. I'm coming from Objective C where the following is perfectly legal:
ALuint * sources;
sources=malloc(sizeof(ALuint)*32);
However, in C++ the compiler says "Assigning to ALuint * from incompatible type void *".
I get that the memory returned from malloc
is not casted as my particular type, and I get that C++ is strict with types.
Now, I could do this:
sources=(ALuint*)malloc(sizeof(ALuint)*32);
But I have read much wiser coders than myself say never to cast in such a manner. Why not? And if not, when or how is the best time or method to make this work?