aakash-sahai / nanopb

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

Add casts for C++ compatibility #27

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
With some toolchains, it may be useful to build nanopb using a C++ compiler. 
This may however give errors, as in C it is ok to implicitly cast void* to 
another pointer.

Adding a few casts here and there will fix this. Also need to add a testcase 
that compiles pb_encode.c and pb_decode.c using g++.

Original issue reported on code.google.com by Petteri.Aimonen on 24 Aug 2012 at 6:36

GoogleCodeExporter commented 9 years ago
I fully agree.
When compiling current master branch code under G++ with -Wcast-qual switch, 
there are plenty of warning in pb_encode.c and one in pb_decode.c stating that 
const qualifier is discarded.

E.g.:
(...)\pb_encode.c: In function 'pb_encode':
(...)\pb_encode.c:171:22: warning: cast discards '__attribute__((const))' 
qualifier from pointer target type [-Wcast-qual]

I guess all of them can be easily 'fixed' by using const declarations.

Original comment by Adam.Cha...@gmail.com on 26 Aug 2012 at 12:03

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

Original comment by Petteri.Aimonen on 26 Aug 2012 at 12:22

GoogleCodeExporter commented 9 years ago
Ah, good to know about -Wcast-qual. I fixed the warnings and added it to the 
tests/Makefile for the library core. It helps to catch any mistaken writes to 
structure in the encoder.

Apparently there wasn't that much to fix for C++ compilation, but now that is 
also part of the test set.

Original comment by Petteri.Aimonen on 26 Aug 2012 at 12:25

GoogleCodeExporter commented 9 years ago
Fix released in nanopb-0.1.6.

Original comment by Petteri.Aimonen on 3 Sep 2012 at 5:46