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

Malloc Prob

This topic is 6149 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

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