[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-trivial] [PATCH 3/3] maint: Fix macros with broken 'do/while(0
From: |
Dr. David Alan Gilbert |
Subject: |
Re: [Qemu-trivial] [PATCH 3/3] maint: Fix macros with broken 'do/while(0); ' usage |
Date: |
Thu, 30 Nov 2017 14:56:30 +0000 |
User-agent: |
Mutt/1.9.1 (2017-09-22) |
* Eric Blake (address@hidden) wrote:
> The point of writing a macro embedded in a 'do { ... } while (0)'
> loop 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;
> the use of do/while (0) in a macro is absolutely essential for the
> purpose of avoiding a syntax error on the 'else' - but it only works
> if there is no trailing ';' in the macro (as the ';' in the code
> calling the macro would then be a second statement and cause the
> 'else' to not pair to the 'if').
>
> Many of the places touched in this code are examples of the ugly
> bit-rotting debug print statements; cleaning those up is left as
> a bite-sized task for another day.
>
> Found mechanically via: $ git grep -B1 'while (0);' | grep -A1 \\\\
>
> Signed-off-by: Eric Blake <address@hidden>
> ---
> diff --git a/migration/rdma.c b/migration/rdma.c
> index ca56594328..9d5a424011 100644
> --- a/migration/rdma.c
> +++ b/migration/rdma.c
> @@ -88,7 +88,7 @@ static uint32_t known_capabilities =
> RDMA_CAPABILITY_PIN_ALL;
> } \
> return rdma->error_state; \
> } \
> - } while (0);
> + } while (0)
Acked-by: Dr. David Alan Gilbert <address@hidden>
--
Dr. David Alan Gilbert / address@hidden / Manchester, UK