This is the mail archive of the
mailing list for the binutils project.
[RFC] Use fputc in place of putc to avoid -Wunused-value warning.
- From: Joel Brobecker <brobecker at adacore dot com>
- To: binutils at sourceware dot org
- Cc: Joel Brobecker <brobecker at adacore dot com>
- Date: Tue, 7 May 2013 07:32:11 -0400
- Subject: [RFC] Use fputc in place of putc to avoid -Wunused-value warning.
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.c (_bfd_default_error_handler): Replace use of putc
by fputc. Add comment explaining why.
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
@@ -733,7 +733,9 @@ _bfd_default_error_handler (const char *fmt, ...)
vfprintf (stderr, new_fmt, 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);