Question
Return an array of objects from a C function?
I'd like to know how to return an array of objects from a C function.
Here's an example:
SDL_Vertex initTriangle (struct Point2D point1, struct Point2D point2, struct Point2D point3) {
SDL_Vertex triangleVertex[3]=
{
{
{ new_point1.x,new_point1.y },
{ 255, 255, 0, 0xFF },
{ 0.f, 0.f }
},
{
{ new_point2.x, new_point2.y },
{ 0,255,255, 0xFF },
{ 0.f, 0.f }
},
{
{ new_point3.x, new_point3.y },
{ 255,0,255, 0xFF },
{ 0.f, 0.f }
}
};
return triangleVertex;
};
SDL_Vertex triangleVertex[3] = initTriangle(...);
SDL_RenderGeometry(renderer, NULL, triangleVertex, 3, NULL, 0);
I'd like to do something like that, but I need to make the function return an object as if I was making this :
SDL_Vertex triangleVertex[3]=
{
{
{ new_point1.x,new_point1.y },
{ 255, 255, 0, 0xFF },
{ 0.f, 0.f }
},
{
{ new_point2.x, new_point2.y },
{ 0,255,255, 0xFF },
{ 0.f, 0.f }
},
{
{ new_point3.x, new_point3.y },
{ 255,0,255, 0xFF },
{ 0.f, 0.f }
}
};
SDL_RenderGeometry(renderer, NULL, triangleVertex, 3, NULL, 0);