This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Marking of functions with attributes like __wur


Roland McGrath <roland@hack.frob.com> writes:

>> I agree 100%.  Alas, the GCC developers don't want to make it easy to
>> ignore __wur.  In Gnulib we have found a way to suppress its warnings
>> selectively, but our technique is ugly and I'm worried that if we
>> publicize it too much the GCC developers will change GCC to warn even
>> when our hack is used.

> Then perhaps we can get another attribute added that is not so strict.

I'm not a glibc developer, just a random curious user, but since I ran
into this recently, I've been following this discussion with interest.
Where I encountered this issue was with write(), namely with monitoring
code that was probing an NNTP (or POP) server.  When finished, it does:

    write(sd, "quit\r\n", 6);
    close(sd);

This produces the warning about the return value of write() being ignored.
But in this case the write is only to do a clean shutdown of the server,
and there's nothing meaningful for the client to do if the write fails.

I initially tried to use a (void) cast to silence the warning, which of
course doesn't work.  I understand the reasons why GCC declines to honor
the (void) cast, but I'm not sure I agree with them.  Yes, people overuse
the (void) cast, but people are going to overuse any method of suppressing
a warning.  The point of warnings is to help people who care about them;
if they don't care enough to investigate the warning and take appropriate
action, they're not likely to benefit from the warning regardless.

I'm currently doing:

    /* Only for clean shutdown, don't care about failure. */
    if (write(sd, "quit\r\n", 6) < 0) {}
    close(sd);

which works and may be the hack that Paul refers to.  I'd be happy to have
to label this line in some way, since indeed most of the time I do care
about the return value from write(), but a (void) cast would have been
sufficient from my perspective.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]