I keep seeing people say we should not be casting mallocs and its family of functions, but I'm having trouble getting this to work without a cast:
Code:
if( geo->num_triangles > geo->tlist_capacity )
{
// Double the list size
if(( new_tlist = (Triangle **)realloc( geo->tlist, geo->num_triangles * 2 * sizeof( Triangle * ))) == NULL )
{
disp_error( "Error allocating memory for vlist\n", __FILE__, __LINE__ );
geo->num_triangles--;
return false;
}
geo->tlist = new_tlist;
geo->tlist_capacity = geo->num_triangles * 2;
}
And similarly (from the same function):
Code:
// Allocate for the new triangle
if(( new_triangle = (Triangle *)malloc(sizeof(Triangle))) == NULL )
{
disp_error( "Error allocating for new triangle\n", __FILE__, __LINE__ );
return false;
}
How would I allocate for structures or arrays of structures without a cast? I'm getting mismatch errors without a cast.