[sclug] Re: [bristol] GCC extensions
Alex Butcher
lug at assursys.co.uk
Thu Oct 27 22:14:12 UTC 2005
On Thu, 27 Oct 2005, ashley Pittman wrote:
>
> On 27 Oct 2005, at 12:44, Alex Butcher wrote:
>> " __must_check int f (void) { ... }
>>
>> This attribute instructs GCC to generate a warning whenever the return
>> value
>> from the function is not stored or used in an expression during invocation.
>> This allows functions whose return value is crucial to ensure that the
>> value
>> is always used.
>
> Isn't this what lint is for?
Not quite; I see a subtle difference.
Scenario:
=========
libfoo, a library that provides a number of functions, some of which diddle
with hardware
fooapp, an application that uses libfoo.
The author of libfoo provides a function x() which must be called, and must
succeed before function y() can be used. She knows that developers don't
always read (or understand) the documentation that she provides, if she can be
bothered to write it at all. She would like to provide a hint to application
developers, such as the developer of fooapp that checking the return code
from x() is important. By flagging x() with __must_check, she can generate
warnings if fooapp's developer attempts to call x() without checking the
return code.
Alternatively, if __must_check isn't used, it's down to fooapp's developer
to remember to run lint on his code. If he even has lint on his system...
$ which lint
/usr/bin/which: no lint in
(/usr/kerberos/bin:/usr/lib/ccache/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/alex/bin)
> Ashley,
Best Regards,
Alex.
--
Alex Butcher Brainbench MVP for Internet Security: www.brainbench.com
Bristol, UK Need reliable and secure network systems?
PGP/GnuPG ID:0x271fd950 <http://www.assursys.com/>
More information about the Sclug
mailing list