gcc - initializing a structure array in c with #define -
the following code gives me warning:
tag_info.h:17: warning: missing braces around initializer tag_info.h:17: warning: (near initialization âtag_list_data[0].subtagsâ) i have tried alot of things nothing seems working. can please suggest something
typedef struct attr{ char attr_name[64]; value_type_t value; int mandatory; }attr_t; typedef struct tags { unsigned int tag_id; attr_t *attr_list; char *tag_name; int tag_type; int subtags[html_subtag_num]; }tags_t; tags_t tag_list_data[150] = { #include "tag_info.h" {0,0,0,0,0} }; "tag_info.h" contains : #if defined(tag_define) #undef tag_define #else #define tag_define(a,b,c,...) {.tag_id=a, .tag_name=#b, .tag_type=c, ##__va_args__} #endif tag_define(0,tag_none,0,0), tag_define(1,!--,0,0), tag_define(2,!doctype,0,0), tag_define(3,a, 1, 1, 117, 59,11,118,92,100),
you initializing subtags if multiple members of tags struct:
typedef struct tags { ... int subtags_0; int subtags_1; int subtags_2; } tags_t; tags_t t = { ..., 0, 1, 2 }; but array. should initialize single entity.
typedef struct tags { ... int subtags[html_subtag_num]; } tags_t; tags_t t = { .tag_id = 0, ..., { 0, 1, 2 } }; // or tags_t t = { .tag_id = 0, ..., .subtags = { 0, 1, 2 } }; also, don't need use concatenation (##)
#define tag_define(a,b,c,...) { ..., ## __va_args__} in end, should like
#define tag_define(a,b,c,...) { ..., .subtags = { __va_args__ } } ... tags_t tag_list_data[150] = { ... { 0,0,0,0,{0}} } instead of
#define tag_define(a,b,c,...) { ..., ##__va_args__} ... tags_t tag_list_data[150] = { ... { 0,0,0,0,0 } }
Comments
Post a Comment