From 9c1eaaeb49d69aaffe5ac2838adee89a1ec779a7 Mon Sep 17 00:00:00 2001 From: Alexey Date: Sun, 5 Apr 2020 13:31:25 +0300 Subject: [PATCH] cgen: declare empty structs correctly --- vlib/v/gen/cgen.v | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 3bd7d88d96..d34e908447 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -2168,10 +2168,14 @@ fn (g mut Gen) write_types(types []table.TypeSymbol) { info := typ.info as table.Struct // g.definitions.writeln('typedef struct {') g.definitions.writeln('struct $name {') - for field in info.fields { - type_name := g.typ(field.typ) - field_name := c_name(field.name) - g.definitions.writeln('\t$type_name $field_name;') + if info.fields.len > 0 { + for field in info.fields { + type_name := g.typ(field.typ) + field_name := c_name(field.name) + g.definitions.writeln('\t$type_name $field_name;') + } + } else { + g.definitions.writeln('EMPTY_STRUCT_DECLARATION;') } // g.definitions.writeln('} $name;\n') //