On Tue, Jan 04, 2011 at 03:04:14PM +0000, PÃdraig Brady wrote: > On 04/01/11 14:37, Karel Zak wrote: > > On Tue, Jan 04, 2011 at 11:53:21AM +0000, PÃdraig Brady wrote: > >> On 01/01/11 22:56, Karel Zak wrote: > >>> On Sat, Jan 01, 2011 at 08:59:02PM +0000, Jon Grant wrote: > >>>> Just building latest code and saw the compiler generated some > >>>> warnings. Just thinking, one idea is to check the return value, and > >>> > >>> the warn_unused_result for write() in glibc is pretty idiotic... > >>> > >>>> use it as best possible (even just for trace) or (void)bytes to make > >>>> it go quiet when there really is no use. > >>> > >>> (void) foo() is mess and it has no effect for warn_unused_result > >>> > >>>> bytes = write(1, "\n", 1); > >>> > >>> hmm.. possible solution is to call error() (but I'm not sure if this > >>> is appropriate solution for unimportant things like /etc/issue) or > >>> really ignore the return value. It would be nice to have a macro that > >>> allows to ignore the return values in some cases > >>> > >>> ignore_result( write(1, "\n", 1) ); > >> > >> We use something like that in coreutils: > >> http://git.sv.gnu.org/gitweb/?p=gnulib.git;a=blob;f=lib/ignore-value.h;hb=HEAD > > > > Nice, but it does not work for all types, what about: > > > > #define ignore(x) ({ typeof(x) __rc = (x); }) > > That looks right for util-linux but > is probably not portable enough for gnulib. Good point. > Also I'd be slightly worried that clang-analyzer > would start complaining about dead stores with that. It seems that clang is not so pedantic, but gcc -Wall prints warning about unused variable â__fooâ, so it's necessary to use the variable somehow... $ cat a.c #include <stdio.h> static int __attribute__((warn_unused_result)) foo(void) { return 0; }; #define ignore(x) ({ typeof(x) __foo = (x); (void) __foo; }) int main(int argc, char **argv) { ignore( foo() ); return 0; } $ scan-build gcc -c a.c ANALYZE: a.c foo ANALYZE: a.c main scan-build: Removing directory '/tmp/scan-build-2011-01-04-1' because it contains no reports. > Perhaps this might work? > > static inline void _ignore (int i) { (void) i; } > #define ignore(x) _ignore ((int)x) I don't think so, it will produce warnings about cast from pointer to integer if the function (foo() in my example) returns a pointer. Karel -- Karel Zak <kzak@xxxxxxxxxx> http://karelzak.blogspot.com -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html