Add a dummy field if struct would otherwise be empty.
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Wed, 6 Mar 2013 16:02:57 +0000 (18:02 +0200)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Wed, 6 Mar 2013 16:02:57 +0000 (18:02 +0200)
Update issue 64
Status: FixedInGit

generator/nanopb_generator.py

index c3b5fbe..663745a 100644 (file)
@@ -300,6 +300,12 @@ class Message:
     
     def __str__(self):
         result = 'typedef struct _%s {\n' % self.name
+
+        if not self.ordered_fields:
+            # Empty structs are not allowed in C standard.
+            # Therefore add a dummy field if an empty message occurs.
+            result += '    uint8_t dummy_field;'
+
         result += '\n'.join([str(f) for f in self.ordered_fields])
         result += '\n}'