Add check for sizeof(double) == 8.
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Thu, 7 Feb 2013 15:48:50 +0000 (17:48 +0200)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Thu, 7 Feb 2013 15:48:50 +0000 (17:48 +0200)
Update issue 54
Status: FixedInGit

generator/nanopb_generator.py

index d35a425..48239c1 100644 (file)
@@ -512,6 +512,7 @@ def generate_header(dependencies, headername, enums, messages):
             yield '       setting PB_MAX_REQUIRED_FIELDS to %d or more.\n' % largest_count
             yield '#endif\n'
     
+    # Add checks for numeric limits
     worst = 0
     worst_field = ''
     checks = []
@@ -549,6 +550,20 @@ def generate_header(dependencies, headername, enums, messages):
                 yield 'STATIC_ASSERT((%s), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_%s)\n'%(assertion,msgs)
             yield '#endif\n'
     
+    # Add check for sizeof(double)
+    has_double = False
+    for msg in messages:
+        for field in msg.fields:
+            if field.ctype == 'double':
+                has_double = True
+    
+    if has_double:
+        yield '\n'
+        yield '/* On some platforms (such as AVR), double is really float.\n'
+        yield ' * These are not directly supported by nanopb, but see example_avr_double.\n'
+        yield ' */\n'
+        yield 'STATIC_ASSERT(sizeof(double) == 8, DOUBLE_MUST_BE_8_BYTES)\n'
+    
     yield '\n#ifdef __cplusplus\n'
     yield '} /* extern "C" */\n'
     yield '#endif\n'