bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] binary-io: always define SET_BINARY as an expression


From: Bruno Haible
Subject: Re: [PATCH] binary-io: always define SET_BINARY as an expression
Date: Thu, 24 Dec 2009 22:19:12 +0100
User-agent: KMail/1.9.9

Eric Blake wrote:
> > For me, with -Wall, plain 0 as a statement provokes a warning
> > "statement with no effect", but writing (void) 0 suppresses that
> > warning.
> 
> Which implies the need for:
> 
> # define SET_BINARY(fd) ((void) 0)

Yes, I agree. And when the result type is 'void', it should be 'void' in all
cases. A Google codesearch reveals that no one is using the SET_BINARY macro
for its value, so this is safe. Applied as follows:


2009-12-24  Bruno Haible  <address@hidden>

        binary-io: Avoid gcc warning due to SET_BINARY.
        * lib/binary-io.h (SET_BINARY): Cast the result to void.
        Reported by Jim Meyering <address@hidden>. Suggestion by Eric Blake.

--- lib/binary-io.h.orig        Thu Dec 24 22:13:34 2009
+++ lib/binary-io.h     Thu Dec 24 22:11:50 2009
@@ -36,6 +36,9 @@
 # undef O_BINARY
 # undef O_TEXT
 #endif
+
+/* SET_BINARY (fd);
+   changes the file descriptor fd to perform binary I/O.  */
 #if O_BINARY
 # if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
 #  include <io.h> /* declares setmode() */
@@ -49,15 +52,15 @@
    /* Avoid putting stdin/stdout in binary mode if it is connected to
       the console, because that would make it impossible for the user
       to interrupt the program through Ctrl-C or Ctrl-Break.  */
-#  define SET_BINARY(fd) (!isatty (fd) ? (setmode (fd, O_BINARY), 0) : 0)
+#  define SET_BINARY(fd) ((void) (!isatty (fd) ? (setmode (fd, O_BINARY), 0) : 
0))
 # else
-#  define SET_BINARY(fd) setmode (fd, O_BINARY)
+#  define SET_BINARY(fd) ((void) setmode (fd, O_BINARY))
 # endif
 #else
   /* On reasonable systems, binary I/O is the default.  */
 # undef O_BINARY
 # define O_BINARY 0
-# define SET_BINARY(fd) /* nothing */
+# define SET_BINARY(fd) /* do nothing */ ((void) 0)
 #endif
 
 #endif /* _BINARY_H */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]