From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eL6Mc-0004gG-FK for qemu-devel@nongnu.org; Sat, 02 Dec 2017 06:53:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eL6Mb-0001Wh-Jk for qemu-devel@nongnu.org; Sat, 02 Dec 2017 06:53:46 -0500 From: Juan Quintela In-Reply-To: <20171201232433.25193-7-eblake@redhat.com> (Eric Blake's message of "Fri, 1 Dec 2017 17:24:32 -0600") References: <20171201232433.25193-1-eblake@redhat.com> <20171201232433.25193-7-eblake@redhat.com> Reply-To: quintela@redhat.com Date: Sat, 02 Dec 2017 12:53:28 +0100 Message-ID: <87wp25qrbb.fsf@secure.laptop> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v2 6/7] maint: Fix macros with broken 'do/while(0); ' usage List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: qemu-devel@nongnu.org, armbru@redhat.com, qemu-trivial@nongnu.org, pbonzini@redhat.com, Gerd Hoffmann , Alistair Francis , Peter Crosthwaite , Kevin Wolf , Max Reitz , "Edgar E. Iglesias" , Peter Maydell , Alexander Graf , Jason Wang , Subbaraya Sundeep , Stefan Berger , "Dr. David Alan Gilbert" , Christian Borntraeger , Cornelia Huck , Richard Henderson , "Michael S. Tsirkin" , Igor Mammedov , "open list:Block layer core" , "open list:Xilinx Zynq" , "open list:New World" , "open list:S390" Eric Blake wrote: > The point of writing a macro embedded in a 'do { ... } while (0)' > loop (particularly if the macro has multiple statements or would > otherwise end with an 'if' statement) is so that the macro can be > used as a drop-in statement with the caller supplying the > trailing ';'. Although our coding style frowns on brace-less 'if': > if (cond) > statement; > else > something else; > that is the classic case where failure to use do/while(0) wrapping > would cause the 'else' to pair with any embedded 'if' in the macro > rather than the intended outer 'if'. But conversely, if the macro > includes an embedded ';', then the same brace-less coding style > would now have two statements, making the 'else' a syntax error > rather than pairing with the outer 'if'. Thus, even though our > coding style with required braces is not impacted, ending a macro > with ';' makes our code harder to port to projects that use > brace-less styles. > > The change should have no semantic impact. I was not able to > fully compile-test all of the changes (as some of them are > examples of the ugly bit-rotting debug print statements that are > completely elided by default, and I didn't want to recompile > with the necessary -D witnesses - cleaning those up is left as a > bite-sized task for another day); I did, however, audit that for > all files touched, all callers of the changed macros DID supply > a trailing ';' at the callsite, and did not appear to be used > as part of a brace-less conditional. > > Found mechanically via: $ git grep -B1 'while (0);' | grep -A1 \\\\ > > Signed-off-by: Eric Blake > Acked-by: Cornelia Huck > Reviewed-by: Michael S. Tsirkin > Acked-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela