[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros |
Date: |
Tue, 29 Jan 2013 13:22:39 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) |
Andreas Färber <address@hidden> writes:
> Am 29.01.2013 11:03, schrieb Markus Armbruster:
>> Andreas Färber <address@hidden> writes:
>>
>>> b) Working around an issue resulting from hiding C statements inside a
>>> preprocessor macro is totally backwards compared to properly using the C
>>> language in the first place. Its mechanism for reuse are functions, and
>>> for performance considerations static inline functions.
>>
>> Nobody denies inline functions are to be preferred in many cases.
>>
>> Valid exceptions include cases where we want genericity, which a macro
>> can easily provide, but an inline function can't.
>>
>>> Therefore I disagree with you that b) is not an entirely different
>>> disussion as you repeatedly suggest and that according to a) it is not
>>> *generally* necessary to put do { ... } while (0) into any random macro
>>> that one writes. It depends on the contents and on the context.
>>
>> I don't think Peter suggested to put do ... while (0) into random
>> macros! He asked to put it exactly into *statement-like* macros, as per
>> standard C practice. Most macros are expression-like.
>
> Quoting PMM from last night:
> <<<
> "do ... while (0)" is completely standard practice
> for writing robust macros in C. Patches which don't do that
> should fail code review.
>>>>
>
> This is what sparked the most heated part of this debate! I completely
> object to this generalized statement without restriction to
> statement-like macros.
Well, you quite obviously can't use "do ... while (0)" in any but
statement-like macros!
If you use it in an expression-like macro, it's no longer an expression.
Pointlessly breaks uses in non-statement expression context.
If you use it in a declaration-like macro, it's no longer a declaration,
and the declaration part goes into its own scope, which tends to be
counter-productive.
If you use it in a file-level macro, you get syntax errors.
>> I think you're overstating your case. Statement-like macros should be
>> rare.
>
> This RFC was just a beginning. An average 50%+ of per target-*/ files
> contained macros that were touched here. Even more files are in hw/. Per
> file it was up to ~5 such macro definitions. And my main issue is
> deriving a convention for new files from this discussion.
Stick to established C practice:
1. Avoid statement-like macros when there are superior alternatives,
like inline functions, or expression-like macros.
2. If you have to use a statement-like macro, ensure it expands into a
complete statement regardless of context. The idiomatic technique for
that is "do ... while (0)".
- Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros, (continued)
- Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros, Peter Maydell, 2013/01/28
- Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros, Andreas Färber, 2013/01/28
- Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros, Peter Maydell, 2013/01/28
- Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros, Markus Armbruster, 2013/01/29
- Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros, Andreas Färber, 2013/01/29
- Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros, Peter Maydell, 2013/01/29
- Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros, Andreas Färber, 2013/01/29
- Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros, Blue Swirl, 2013/01/29
- Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros, Markus Armbruster, 2013/01/29
- Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros, Andreas Färber, 2013/01/29
- Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros,
Markus Armbruster <=
[Qemu-devel] [PATCH for-1.4 05/19] target-s390x: Fix debug output, Andreas Färber, 2013/01/27
[Qemu-devel] [PATCH RESEND for-1.4 01/19] target-cris: Build fix for debug output, Andreas Färber, 2013/01/27
[Qemu-devel] [PATCH for-1.4 06/19] target-s390x: Fix debug output (continued), Andreas Färber, 2013/01/27
[Qemu-devel] [PATCH for-1.4 07/19] target-sparc: Fix debug output for DEBUG_MMU, Andreas Färber, 2013/01/27
[Qemu-devel] [PATCH for-1.4? 09/19] target-cris/mmu.c: Update Coding Style of cris_mmu_translate_page(), Andreas Färber, 2013/01/27
[Qemu-devel] [RFC 17/19] target-s390x: Refactor debug output macros, Andreas Färber, 2013/01/27
[Qemu-devel] [RFC 14/19] target-microblaze: Refactor debug output macros, Andreas Färber, 2013/01/27
[Qemu-devel] [PATCH for-1.4 02/19] target-ppc: Fix target_ulong vs. hwaddr format mismatches, Andreas Färber, 2013/01/27