This topic is now archived and is closed to further replies.


type casting error, please help

Recommended Posts

greetings, I am usiing Nate Miller''s tga file loading code. When I try to compile it I keep getting type casting errors. i.e.''='': cannot convert from ''void *'' to ''unsigned char*'' ================================================================ //getRGBA //reads in rgba data for a 32bit image unsigned char *getRGBA (FILE *s, int size) { unsigned char *rgba; unsigned char temp; int bread; int i; // rgba =(unsigned char *) malloc(size * 4); rgba = malloc(size * 4); if (rgba == NULL) return 0; bread = fread(rgba, sizeof(unsigned char), size * 4, s); //tga is stored in bgra, make it rgba if (bread != size * 4) { free (rgba); return 0; } for (i = 0; i < size * 4; i+=4) { temp = rgba; rgba[i] = rgba[1 + 2]; rgba[1 + 2] = temp; } texFormat = GL_RGBA; return rgba; } =============================================================== When i rewrite it to rgba =(unsigned char *) malloc(size * 4); the error goes away. Although, malloc uses a void * and a void pointer is able to point to any type of object. Why do I get the error? Or maybe I just copied the code down wrong. Thanks in advance. ----------------------------- "There are ones that say they can and there are those who actually do." "...u can not learn programming in a class, you have to learn it on your own."

Share this post

Link to post
Share on other sites
rgba = malloc(size * 4);

Hmmm, if its anything like some of the wierd stuff I"ve been experiencing try doing it like this:

rgba= (unsigned char) (malloc(size*4));

I have no idea if that will work... I prefer using ''new'' (which in case you want to know, is easier,
and here is how you do it:

rgba= new unsigned char [size*4];

Trent (ShiningKnight)
E-mail me
OpenGL Game Programming Tutorials

Share this post

Link to post
Share on other sites