Malloc Prob

Started by
1 comment, last by sckoobs 23 years, 1 month ago
Righty, I am trying to load a bitmap and I want to allocate it some memory for the actual bitmap bits.
  

    GLubyte          *bits;

    bits = malloc(bitsize);
	if (bits == NULL)
    {
        // Couldn't allocate memory - return NULL

        free(*info);
        fclose(fp);
        return (NULL);
    }

  
The error I'm getting in (VC++ 6.0) is: "error C2440: '=' : cannot convert from 'void *' to 'unsigned char *' Conversion from 'void*' to pointer to non-'void' requires an explicit cast" Now the declaration of malloc is void malloc(...) but in the example in the help file it shows malloc being used for allocating memory to a pointer to a character i.e:
  

   char *string;

   /* Allocate space for a path name */
   string = malloc( _MAX_PATH );
   if( string == NULL )
      printf( "Insufficient memory available\n" );

  
Any ideas - they will be much appreciated! Max Edited by - sckoobs on March 17, 2001 8:43:12 AM
Advertisement
You need to do what it says, i.e. a cast

GLubyte *bits;
bits = (GLubyte *) malloc(bitsize);

Gee Brain, what we gonna do tonight?
remember that even though your program looks like a C program, you are still compiling it with a C++ compiler, and C++ is more picky about types than C

This topic is closed to new replies.

Advertisement