aakash-sahai / nanopb

Automatically exported from code.google.com/p/nanopb
zlib License
0 stars 0 forks source link

Message with no fields generates empty struct #64

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Write .proto file which includes a message with no fields.
2. Compile that .proto file.

The resulting generated .h file will contain empty structs. These are not 
strictly allowed in C99 (eg. see 
http://stackoverflow.com/questions/2849901/empty-struct-definitions-illegal-in-c
-but-not-c#2849982 ). GCC allows it anyway, but MSVC does not.

Here's a possible patch which adds a dummy field to such structs:

--- nanopb/generator/nanopb_generator_old.py    2013-03-07 02:24:11 +1100
+++ nanopb/generator/nanopb_generator_new.py    2013-03-07 02:24:14 +1100
@@ -300,6 +300,8 @@

     def __str__(self):
         result = 'typedef struct _%s {\n' % self.name
+               if len(self.ordered_fields) == 0:
+                   result += '    uint8_t dummy; // structs in C must be 
non-empty'
         result += '\n'.join([str(f) for f in self.ordered_fields])
         result += '\n}'

Original issue reported on code.google.com by someon...@gmail.com on 6 Mar 2013 at 3:56

GoogleCodeExporter commented 9 years ago
This issue was updated by revision 5522e02133be.

Original comment by Petteri.Aimonen on 6 Mar 2013 at 4:03

GoogleCodeExporter commented 9 years ago
Fix released in 0.2.1

Original comment by Petteri.Aimonen on 14 Apr 2013 at 7:19