Jump to content

  • Log In with Google      Sign In   
  • Create Account

type casting error, please help


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 cMADsc   Members   -  Reputation: 122

Like
Likes
Like

Posted 30 July 2001 - 09:19 AM

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."



Sponsor:

#2 mittens   Moderators   -  Reputation: 1315

Like
Likes
Like

Posted 30 July 2001 - 03:17 PM

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

#3 zedzeek   Members   -  Reputation: 528

Like
Likes
Like

Posted 31 July 2001 - 09:56 AM

its cause youre using c++. the above error won''t happen with c. c++ has more rigorous type checking, so stick a cast before it




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS