don't write out empty structs
"struct { } foo" is not valid ISO C99; while gcc/clang/icc support it,
other compilers and tools don't (e.g. pycparser)
This commit is contained in:
parent
90c3473406
commit
e9df12b387
1 changed files with 12 additions and 4 deletions
|
|
@ -878,6 +878,18 @@ static void define_group(struct strings *s, struct node *n, const char *group_na
|
|||
/* named union is where all group members are in the union */
|
||||
int named_union = (group_name && ulen == flen && ulen > 0);
|
||||
int named_struct = (group_name && !named_union);
|
||||
int empty = 1;
|
||||
|
||||
for (f = n->fields; f < n->fields + flen; f++) {
|
||||
decode_value(&f->v, f->f.slot.type, f->f.slot.defaultValue, NULL);
|
||||
if (f->v.t.which != Type__void)
|
||||
empty = 0;
|
||||
}
|
||||
|
||||
if (named_struct && empty) {
|
||||
str_addf(&s->decl, "%s/* struct { -empty- } %s; */\n", s->dtab.str, group_name);
|
||||
return;
|
||||
}
|
||||
|
||||
if (named_struct) {
|
||||
str_addf(&s->decl, "%sstruct {\n", s->dtab.str);
|
||||
|
|
@ -888,10 +900,6 @@ static void define_group(struct strings *s, struct node *n, const char *group_na
|
|||
str_addf(&s->var, "%s.", group_name);
|
||||
}
|
||||
|
||||
for (f = n->fields; f < n->fields + flen; f++) {
|
||||
decode_value(&f->v, f->f.slot.type, f->f.slot.defaultValue, NULL);
|
||||
}
|
||||
|
||||
/* fields before the union members */
|
||||
for (f = n->fields; f < n->fields + flen && !in_union(f); f++) {
|
||||
define_field(s, f);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue