[alsa-devel] [WIP PATCH] Scarlett mixer interface for 6i6, 18i6, 18i8 and 18i20.

Takashi Iwai tiwai at suse.de
Thu Oct 9 10:39:06 CEST 2014


At Wed, 08 Oct 2014 23:21:54 +0200,
Robin Gareus wrote:
> 
> > +#define CTL_SWITCH(cmd, off, no, count, name) \
> > +	do { \
> > +		err = add_new_ctl(mixer, &usb_scarlett_ctl_switch, cmd, off, no, 2,
> count, name, NULL, &elem); \
> > +		if (err < 0) \
> > +			return err; \
> > +	} while (0)
> 
> curious, why "do { } while (0)" and not just  "{ }" ?

It's a standard trick to make the macro working with if/else in kernel
codes.

Suppose a macro like

#define FOO() { .... }

and use it like

	if (something)
		FOO();
	else
		bar();

then you'll get a build error.
But it can be avoided by surrounding do and while (0). 

#define FOO() do { .... } while (0)


Takashi


More information about the Alsa-devel mailing list