Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array type has incomplete element type

Tags:

c

I'm trying to do this:

typedef struct {
    float x;
    float y;
} coords;
struct coords texCoordinates[] = { {420, 120}, {420, 180}};

But the compiler won't let me. : ( What's wrong with this declaration? Thanks for your help!

like image 340
Matt N. Avatar asked Aug 05 '11 14:08

Matt N.


1 Answers

Either do:


typedef struct {
    float x;
    float y;
} coords;
coords texCoordinates[] = { {420, 120}, {420, 180}};

OR


struct coords {
    float x;
    float y;
};
struct coords texCoordinates[] = { {420, 120}, {420, 180}};

In C, struct names reside in a different name space than typedefs.

Of course you can also use typedef struct coords { float x; float y; } coords; and use either struct coords or coords. In this case it won't matter what you choose, but for self-referencing structures you need a struct name:

struct list_node {
    struct list_node* next; // reference this structure type - need struct name    
    void * val;
};
like image 134
user786653 Avatar answered Sep 25 '22 20:09

user786653