Reputation: 551
I copy some code from another project and I work fine in previous project but in new project I get linking error:
OpengLWaveFrontCommon.h:50:22: error: cannot initialize a variable of type 'VertexTextureIndex *' with an rvalue of type 'void *' VertexTextureIndex *ret = malloc(sizeof(VertexTextureIndex));
This file (OpengLWaveFrontCommon.h) is a part of openGL iPhone project: Wavefront OBJ Loader. https://github.com/jlamarche/iOS-OpenGLES-Stuff
Should I make some special flag or something, because it is C structured?
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
typedef struct {
GLfloat red;
GLfloat green;
GLfloat blue;
GLfloat alpha;
} Color3D;
static inline Color3D Color3DMake(CGFloat inRed, CGFloat inGreen, CGFloat inBlue, CGFloat inAlpha)
{
Color3D ret;
ret.red = inRed;
ret.green = inGreen;
ret.blue = inBlue;
ret.alpha = inAlpha;
return ret;
}
#pragma mark -
#pragma mark Vertex3D
#pragma mark -
typedef struct {
GLfloat x;
GLfloat y;
GLfloat z;
} Vertex3D;
typedef struct {
GLuint originalVertex;
GLuint textureCoords;
GLuint actualVertex;
void *greater;
void *lesser;
} VertexTextureIndex;
static inline VertexTextureIndex * VertexTextureIndexMake (GLuint inVertex, GLuint inTextureCoords, GLuint inActualVertex)
{
VertexTextureIndex *ret = malloc(sizeof(VertexTextureIndex));
ret->originalVertex = inVertex;
ret->textureCoords = inTextureCoords;
ret->actualVertex = inActualVertex;
ret->greater = NULL;
ret->lesser = NULL;
return ret;
}
Upvotes: 0
Views: 4674
Reputation: 107131
Cause Of Issue:
malloc()
returns a pointer of type void *
, you need to type cast it to corresponding data-type.
malloc returns a void pointer to the allocated space, or NULL if there is insufficient memory available. To return a pointer to a type other than void, use a type cast on the return value. The storage space pointed to by the return value is guaranteed to be suitably aligned for storage of any type of object that has an alignment requirement less than or equal to that of the fundamental alignment.
Reference malloc()
Fix for the Issue:
VertexTextureIndex *ret = (VertexTextureIndex *)malloc(sizeof(VertexTextureIndex));
Upvotes: 5