Archived

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

sckoobs

Malloc Prob

Recommended Posts

sckoobs    157
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

Share this post


Link to post
Share on other sites
kvh    122
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

Share this post


Link to post
Share on other sites