This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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]

[RFC] Use fputc in place of putc to avoid -Wunused-value warning.


Hello,

Currently, bfd does not compile with -Wunused-value because
the following code:

        val = putc ('\n', f);

gets expanded into some code that triggers a warning:

        warning: value computed is not used [-Wunused-value]

This is because putc is implemented as a macro...

>#define putc(__x, __p)  (((!((__p)->_flag & 0xC000)) && \
>                        ((__p)->_flag = ((__p)->_flag  & 0x3FFF) | 0x8000)),\
>                        (--(__p)->_cnt < 0 ? \
>                        __flsbuf((unsigned char) (__x), (__p)) : \
>                        (int) (*(__p)->_ptr++ = (unsigned char) (__x))))

It's the first part, before the coma operator, which triggers
the unused-value warning.

I am not sure how we want to avoid this sort of issue, whether
in a general way, or just dealing with each instance. There is
currently only one warning on AIX, and that is the one call to putc
in bfd.c.  One could do:

    (fputc) ('\n', stderr);

Or else we could simply use fputc in this case.

bfd/ChangeLog:

        * bfd.c (_bfd_default_error_handler): Replace use of putc
        by fputc.  Add comment explaining why.

Thoughts?

Thank you,
-- 
Joel

---
 bfd/bfd.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/bfd/bfd.c b/bfd/bfd.c
index 10bc319..8d0580c 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -733,7 +733,9 @@ _bfd_default_error_handler (const char *fmt, ...)
   vfprintf (stderr, new_fmt, ap);
   va_end (ap);
 
-  putc ('\n', stderr);
+  /* On AIX, putc is implemented as a macro that triggers a -Wunused-value
+     warning, so use the fputc function to avoid it.  */
+  fputc ('\n', stderr);
   fflush (stderr);
 }
 
-- 
1.7.0.4


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