Reputation: 6968
just wondering, how do you use global arrays of a structure's?
For example:
int y = 0;
object objectArray [100];
typedef struct object{
time_t objectTime;
int objectNumber;
} object;
int main(void)
{
while(1)
{
time_t time_now;
time_now = time(NULL);
object x = {time_now, objectNo}
objectArray[y] = x;
y++;
}
}
This always throws an "error: array type has incomplete element type", can anybody advise me of the problem and an appropriate solution? Thanks
Upvotes: 1
Views: 10861
Reputation: 471279
Move the definition of the struct to before your declaration of the array:
typedef struct object{
time_t objectTime;
int objectNumber;
} object;
object objectArray [100];
You're getting that error because the compiler doesn't know the size of object
when it gets to the array declaration.
Upvotes: 5