Okay, straight to the point, here is the code:
struct TileStruct
{
SDL_Rect clip[0];
};
TileStruct Tiles[] =
{
{
clip[0].x = 0*TILE,
clip[0].y = 0*TILE,
clip[0].w = TILE,
clip[0].h = TILE
},
{
clip[0].x = 1*TILE,
clip[0].y = 0*TILE,
clip[0].w = TILE,
clip[0].h = TILE
},
{
clip[0].x = 0*TILE,
clip[0].y = 1*TILE,
clip[0].w = TILE,
clip[0].h = TILE
},
{
clip[0].x = 1*TILE,
clip[0].y = 1*TILE,
clip[0].w = TILE,
clip[0].h = TILE
}
};
Error
too many intitializers for 'Load::Vars()::TileStruct'
Btw, TILE is the number 16.
Anyway, I’m not sure how to fix this. I’ve looked it up in several places but can’t seem to find an answer. Can someone explain what’s going wrong here? No downvoting please. I legitimately couldn’t find a solution on the net.
You have declared an array of 0 elements, so you can’t initialize it with anything.
Beside zero-sized arrays are GNU C extension – if it’s really what you need, and if that structure must be placed on stack/global place – you have to manually create memory pad with enough size:
Or use dynamic memory allocator in the same whay (again, if it’s whar you need).
Btw, while zero-sized arrays are GNU specific, unsized arrays are standard to C99 and later (declared as
int some_array[];within structure).