cgen: declare empty structs correctly

pull/4248/head
Alexey 2020-04-05 13:31:25 +03:00 committed by GitHub
parent de701ccfac
commit 9c1eaaeb49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -2168,11 +2168,15 @@ fn (g mut Gen) write_types(types []table.TypeSymbol) {
info := typ.info as table.Struct info := typ.info as table.Struct
// g.definitions.writeln('typedef struct {') // g.definitions.writeln('typedef struct {')
g.definitions.writeln('struct $name {') g.definitions.writeln('struct $name {')
if info.fields.len > 0 {
for field in info.fields { for field in info.fields {
type_name := g.typ(field.typ) type_name := g.typ(field.typ)
field_name := c_name(field.name) field_name := c_name(field.name)
g.definitions.writeln('\t$type_name $field_name;') g.definitions.writeln('\t$type_name $field_name;')
} }
} else {
g.definitions.writeln('EMPTY_STRUCT_DECLARATION;')
}
// g.definitions.writeln('} $name;\n') // g.definitions.writeln('} $name;\n')
// //
g.definitions.writeln('};\n') g.definitions.writeln('};\n')