1

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

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.