From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47964) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmeR6-0002wx-L6 for qemu-devel@nongnu.org; Wed, 21 Sep 2016 06:07:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bmeR2-0002a2-0i for qemu-devel@nongnu.org; Wed, 21 Sep 2016 06:07:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60888) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmeR1-0002Zi-Mn for qemu-devel@nongnu.org; Wed, 21 Sep 2016 06:07:23 -0400 Date: Wed, 21 Sep 2016 11:07:18 +0100 From: "Daniel P. Berrange" Message-ID: <20160921100718.GO15535@redhat.com> Reply-To: "Daniel P. Berrange" References: <1474391326-871-1-git-send-email-felipe@nutanix.com> <000301d213c7$7142f980$53c8ec80$@ru> <87y42l93dr.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Felipe Franciosi Cc: Markus Armbruster , Pavel Dovgalyuk , qemu-devel , Pavel Dovgalyuk On Wed, Sep 21, 2016 at 10:00:23AM +0000, Felipe Franciosi wrote: > > > On 21 Sep 2016, at 07:24, Markus Armbruster wrote: > > > > "Pavel Dovgalyuk" writes: > > > >>> From: Felipe Franciosi [mailto:felipe@nutanix.com] > >>> If compiling with -Werror=unused-result, replay-internal.c won't build > >>> due to a call to fwrite() where the returned value is ignored. A simple > >>> cast to (void) is not sufficient on recent GCCs, so this fixes it. > >>> > >>> Signed-off-by: Felipe Franciosi > >>> --- > >>> replay/replay-internal.c | 2 +- > >>> 1 file changed, 1 insertion(+), 1 deletion(-) > >>> > >>> diff --git a/replay/replay-internal.c b/replay/replay-internal.c > >>> index 5835e8d..6978d76 100644 > >>> --- a/replay/replay-internal.c > >>> +++ b/replay/replay-internal.c > >>> @@ -65,7 +65,7 @@ void replay_put_array(const uint8_t *buf, size_t size) > >>> { > >>> if (replay_file) { > >>> replay_put_dword(size); > >>> - fwrite(buf, 1, size, replay_file); > >>> + (void)(fwrite(buf, 1, size, replay_file)+1); > >>> } > >>> } > >> > >> This looks very weird. > > Oh I couldn't agree more. I hate this syntax. It is, however, the simplest way to get around this issue. See: > http://stackoverflow.com/questions/11888594/ignoring-return-values-in-c If we want to ignore return value reliably, lets just pull in the ignore_value macro from gnulib which is known to work across GCC versions /* Normally casting an expression to void discards its value, but GCC versions 3.4 and newer have __attribute__ ((__warn_unused_result__)) which may cause unwanted diagnostics in that case. Use __typeof__ and __extension__ to work around the problem, if the workaround is known to be needed. */ #if 3 < __GNUC__ + (4 <= __GNUC_MINOR__) # define ignore_value(x) \ (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; })) #else # define ignore_value(x) ((void) (x)) #endif GNULIB makes it availavble under LGPLv2.1+ eg used as: ignore_value(fwrite(buf, 1, size, replay_file)); Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|