9 Oct
2014
9 Oct
'14
10:39 a.m.
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