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