mlot / nanopb

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

Define checkreturn in the header file #109

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Write a function that doesn't check the return value of e.g. pb_write
2. Compile

Expected: Compiler warning (with GCC)
Actual result: no warning

The __attribute__((warn_unused_result)) has to be used in the header file in 
order to be visible to callers. Instead it's used in the .c files.

Original issue reported on code.google.com by bernhard...@gmail.com on 18 Mar 2014 at 2:30

GoogleCodeExporter commented 9 years ago
I haven't wanted to force these warnings on everybody, they are more about 
verifying that internally every error is properly handled.

I'm not sure if putting these in the header file would be a good idea. I 
haven't seen any other C library do such a thing.

Original comment by Petteri.Aimonen on 18 Mar 2014 at 4:39

GoogleCodeExporter commented 9 years ago
Currently it is quite difficult to suppress the warn_unused_result warning in 
GCC. The normal (void)function() approach does not work.

Therefore defining these in the public header could cause false positives that 
would be difficult to fix. Lint or splint can be used to get warnings about the 
unused return values.

Original comment by Petteri.Aimonen on 2 Apr 2014 at 6:31