Not logged in
Log in now
Create an account
Subscribe to LWN
Pencil, Pencil, and Pencil
Dividing the Linux desktop
LWN.net Weekly Edition for June 13, 2013
A report from pgCon 2013
Little things that matter in language design
>Also, (void)blah is *really ugly*. To me casts to void look *wrong*.
ignore_unwanted_result = unlink(filename);
Which would you prefer?
Posted Nov 24, 2006 21:58 UTC (Fri) by nix (subscriber, #2304)
The problem with (in effect) adding that attribute to every function is
that it *would* require one ugly workaround or another, and thus would
encourage using such workarounds even for those functions where it *is* an
error to ignore the result. This would eliminate a large part of the point
of warn_unused_result, and reduce net security.
(I've seen exactly this happen on codebases that frequently get attacked
by IMHO flawed lint tools that *do* emit such warnings as you propose.
(void)foo() crops up whenever foo()'s result is ignored, *even when
ignoring that result is in fact a bad idea*.)
Posted Nov 30, 2006 2:05 UTC (Thu) by ldo (subscriber, #40946)
>Since the whole point of __attribute__((warn_unused_result)) is that
>it should be applied only to functions where it is nearly always a
>mistake to ignore the result at all, the question is academic.
On the contrary, the question is far from academic. This business of having to ignore return values by assigning them to rubbish variables (as opposed to simply casting them to void) has already infected the Linux kernel--and indeed, led to bugs there. A clean, uniform solution is needed.
Posted Nov 28, 2006 4:30 UTC (Tue) by xoddam (subscriber, #2322)
#define do (void)
Posted Nov 28, 2006 23:56 UTC (Tue) by nix (subscriber, #2304)
Posted Nov 29, 2006 2:03 UTC (Wed) by xoddam (subscriber, #2322)
Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds