[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 6/7] maint: Fix macros with broken 'do/while(
From: |
Juan Quintela |
Subject: |
Re: [Qemu-devel] [PATCH v2 6/7] maint: Fix macros with broken 'do/while(0); ' usage |
Date: |
Sat, 02 Dec 2017 12:53:28 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) |
Eric Blake <address@hidden> 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 <address@hidden>
> Acked-by: Cornelia Huck <address@hidden>
> Reviewed-by: Michael S. Tsirkin <address@hidden>
> Acked-by: Dr. David Alan Gilbert <address@hidden>
Reviewed-by: Juan Quintela <address@hidden>
- [Qemu-devel] [PATCH v2 0/7] macro do/while (0) cleanup, Eric Blake, 2017/12/01
- [Qemu-devel] [PATCH v2 1/7] net: Drop unusual use of do { } while (0);, Eric Blake, 2017/12/01
- [Qemu-devel] [PATCH v2 3/7] chardev: Use goto/label instead of do/break/while(0), Eric Blake, 2017/12/01
- [Qemu-devel] [PATCH v2 4/7] chardev: Clean up previous patch indentation, Eric Blake, 2017/12/01
- [Qemu-devel] [PATCH v2 5/7] tests: Avoid 'do/while(false); ' in vhost-user-bridge, Eric Blake, 2017/12/01
- [Qemu-devel] [PATCH v2 2/7] mips: Tweak location of ';' in macros, Eric Blake, 2017/12/01
- [Qemu-devel] [PATCH v2 7/7] checkpatch: Enforce proper do/while (0) style, Eric Blake, 2017/12/01
- [Qemu-devel] [PATCH v2 6/7] maint: Fix macros with broken 'do/while(0); ' usage, Eric Blake, 2017/12/01
- Re: [Qemu-devel] [PATCH v2 6/7] maint: Fix macros with broken 'do/while(0); ' usage,
Juan Quintela <=