[SCM] Samba Shared Repository - branch master updated

David Disseldorp ddiss at suse.de
Wed May 30 06:58:40 MDT 2012


On Wed, 30 May 2012 14:43:10 +0200
Volker Lendecke <Volker.Lendecke at SerNet.DE> wrote:

> The problem is that there is no canonical replacement, as
> the variety of macros is so large. I can certainly go
> through all the macros and expand them manually, but this
> from my point of view does not provide any additional
> information beyond the "please don't use control-flow
> changing macros".

Perhaps we could add something similar to the relevant section in the
Linux kernel CodingStyle[1] doc:

<quote>
Macros with multiple statements should be enclosed in a do - while block:

#define macrofun(a, b, c) 			\
	do {					\
		if (a == 5)			\
			do_this(b, c);		\
	} while (0)

Things to avoid when using macros:

1) macros that affect control flow:

#define FOO(x)					\
	do {					\
		if (blah(x) < 0)		\
			return -EBUGGERED;	\
	} while(0)

is a _very_ bad idea.  It looks like a function call but exits the "calling"
function; don't break the internal parsers of those who will read the code.

2) macros that depend on having a local variable with a magic name:

#define FOO(val) bar(index, val)
</quote>

Cheers, David

1. http://www.kernel.org/doc/Documentation/CodingStyle


More information about the samba-technical mailing list