wiseveri
wiseveri

Reputation: 291

error: array type has incomplete element type

There are already a few of those threads on here, but none of them actually answer my problem. In my header I have:

 struct table_val  
 {  
    char res;  
    char carry;  
 };  
 typedef struct table_val TABLE_VAL;

and in my source file I try to create this static array of structs:

struct TABLE_VAL add_table[] = {
{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0},
{1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}, {0, 1},
{2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}, {0, 1}, {1, 1},
{3, 0}, {4, 0}, {5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}, {0, 1}, {1, 1}, {2, 1},
{4, 0}, {5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}, {0, 1}, {1, 1}, {2, 1}, {3, 1},
{5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}, {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1},
{6, 0}, {7, 0}, {8, 0}, {9, 0}, {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1},
{7, 0}, {8, 0}, {9, 0}, {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {6, 1},
{8, 0}, {9, 0}, {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, {7, 1},
{9, 0}, {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, {7, 1}, {8, 1}
};

Compiling this leads to the error in the title. Am I not allowed to create an array in that manner? If not, is there a short version, than initializing every struct after creation?

Upvotes: 0

Views: 323

Answers (1)

ouah
ouah

Reputation: 145919

Use

TABLE_VAL add_table[]

or

struct table_val add_table[]

and not

struct TABLE_VAL add_table[]

When you do:

typedef struct table_val TABLE_VAL;

you are creating a type alias named TABLE_VAL for the type struct table_val.

Upvotes: 4

Related Questions