aakash-sahai / nanopb

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

Compiler errors because of non-constant initializers #13

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The issue for me is that my platform's compiler errors when I try               

to initialize an array with non-constant values. It has some ANSI C-isms;       

this is one of them. I did something similar with the decode side; just         

checking because the encode changed in this release.

--- pb_encode.c.orig    2012-06-13 09:32:36.443881585 -0700                     

+++ pb_encode.c 2012-06-13 09:35:59.816378851 -0700                             

@@ -235,8 +235,15 @@                                                            

 bool checkreturn pb_encode_fixed32(pb_ostream_t *stream, const void *value)                                                                
 {                                                                                                                                          
     #ifdef __BIG_ENDIAN__                                                                                                                  
-    uint8_t *bytes = value;                                                    

-    uint8_t lebytes[4] = {bytes[3], bytes[2], bytes[1], bytes[0]};             

+    // Modifications begin                                                     

+    //   Description: compiler is picky about array initialization from        

variables                                                                       

+    uint8_t *bytes = (uint8_t *) value;                                        

+    uint8_t lebytes[4];                                                        

+    lebytes[0] = bytes[3];                                                     

+    lebytes[1] = bytes[2];                                                     

+    lebytes[2] = bytes[1];                                                     

+    lebytes[3] = bytes[0];                                                     

+    // Modifications end                                                       

     return pb_write(stream, lebytes, 4);            

Original issue reported on code.google.com by Petteri.Aimonen on 13 Jun 2012 at 5:06

GoogleCodeExporter commented 9 years ago
Similar patch for decode functions. Also comments can all be removed; I was 
just using them to track modifications in my local source tree.

--- pb_decode.c.orig    2012-02-15 07:34:48.000000000 -0800
+++ pb_decode.c 2012-05-22 12:35:43.520295788 -0700
@@ -475,7 +475,14 @@
     uint8_t bytes[4] = {0};
     bool status = pb_read(stream, bytes, 4);
     if (status) {
-      uint8_t bebytes[4] = {bytes[3], bytes[2], bytes[1], bytes[0]};
+      // Modifications begin
+      //   Description: compiler doesn't like uint8_t bebytes[4] = {bytes[3], 
...}
+      uint8_t bebytes[4];
+      bebytes[0] = bytes[3];
+      bebytes[1] = bytes[2];
+      bebytes[2] = bytes[1];
+      bebytes[3] = bytes[0];
+      // Modifications end
       memcpy(dest, bebytes, 4);
     }
     return status;
@@ -490,8 +497,18 @@
     uint8_t bytes[8] = {0};
     bool status = pb_read(stream, bytes, 8);
     if (status) {
-      uint8_t bebytes[8] = {bytes[7], bytes[6], bytes[5], bytes[4], 
-                            bytes[3], bytes[2], bytes[1], bytes[0]};
+      // Modifications begin
+      //   Description: compiler doesn't like uint8_t bebytes[8] = {bytes[7], 
...}
+      uint8_t bebytes[8];
+      bebytes[0] = bytes[7];
+      bebytes[1] = bytes[6];
+      bebytes[2] = bytes[5];
+      bebytes[3] = bytes[4];
+      bebytes[4] = bytes[3];
+      bebytes[5] = bytes[2];
+      bebytes[6] = bytes[1];
+      bebytes[7] = bytes[0];
+      // Modifications end
       memcpy(dest, bebytes, 8);
     }
     return status;

Original comment by kwo...@gmail.com on 13 Jun 2012 at 6:12

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 7e1059628c1d.

Original comment by Petteri.Aimonen on 13 Jun 2012 at 6:45