The array type has an incomplete element type

I am trying to do this:

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

But the compiler will not allow me.: (What is wrong with this expression? Thanks for your help!

+5
source share
1 answer

Or 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, structnames are in a different namespace 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 does not matter what you choose, but for structures with self-refraction, you need the name of the structure:

struct list_node {
    struct list_node* next; // reference this structure type - need struct name    
    void * val;
};
+14
source

All Articles