开发者

Array type has incomplete element type

开发者 https://www.devze.com 2023-03-26 18:21 出处:网络
I\'m trying to do this: typedef struct { float x; float y; } coords; struct coords texCoordinates[] = { {420, 120}, {420, 180}};

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 le开发者_运维百科t me. : ( What's wrong with this declaration? Thanks for your help!


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;
};
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号