This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Style and Conventions: Multi-line function-like macro formatting.
On Thu, Jan 18, 2018 at 1:43 PM, Joseph Myers <joseph@codesourcery.com> wrote:
> On Thu, 18 Jan 2018, Zack Weinberg wrote:
>
>> I would put it stronger: ({ ... }) is a GCC extension that should be
>> _avoided_ unless absolutely necessary, when neither a do { ... } while
>> (0) block inside a macro nor an inline function will do the job.
>
> I don't see it as a problematic extension, in cases where you do want the
> value returned by the sequence of statements inside ({ }). Preferring
> inline functions applies generically for anything that can readily be
> expressed as an inline function rather than a macro - they're better than
> both ({ }) and do { } while (0) in the cases where they work.
I think we're in violent agreement: An inline function should be used
whenever possible. If it is not possible, use do { } while (0) unless
the macro needs to act like an expression.
The wiki should probably also mention the need to use (__extension__
({ ... })) when the construct appears in public headers.
zw