qemu-devel
[Top][All Lists]
Advanced

[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: Andreas Färber
Subject: Re: [Qemu-devel] [RFC 10/19] target-alpha: Refactor debug output macros
Date: Tue, 29 Jan 2013 09:42:09 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130105 Thunderbird/17.0.2

Am 28.01.2013 22:10, schrieb Peter Maydell:
[lengthy discussion of what may go wrong without do { ... } while (0)]

We seem to to agree to disagree here.

The use of an if (foo) { ... } inside Fred's macro (or my pseudocode?)
was what prompted this whole mess, so there is no need to explain that
to me.

We seem to agree that by badly formulating a macro, bad effects can happen.

Where we disagree is that you suggest that do { ... while (0) is any
better than G_STMT_START ... G_STMT_END. I disagree and find *both*
obscuring the code. I clearly stated why.

Therefore I am interested in a non-obscured solution!

Analysing the reasons for the obscured suggestion:

a) "if (foo) MACRO1(); else MACRO2();" is forbidden by Coding Style.
Thus, if careful review indicates there are no such Coding Style
violations, it is entirely possible not to add any
fault-that-may-not-happen-obscuring macro statements.

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.

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.

FWIW it is pretty similar to the reverse-comparison initiative: It is
addressing an issue that I never run into and that Coding Style
forbidding if ((foo = bar)) { ... } can address just as well, while
keeping things more readable. And that is from my perspective the core
of this discussion: which solution is best *readable*, not what
workaround *may* prevent some kind of error.
Adding parenthesis to avoid operator precedence issues is much less
invasive from my POV than adding two more lines with \ and indentation
inside a macro.

BTW if this discussion were about how to write a single macro inside
alpha code, there would be not much need for this discussion. KVM is
using do { .. } while (0) already. This is about avoiding to
unnecessarily *prescribe* cluttering every single source file in the
tree as you seemed to suggest.

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



reply via email to

[Prev in Thread] Current Thread [Next in Thread]