USB_ATTACH_SETUP macros question

John-Mark Gurney gurney_j at resnet.uoregon.edu
Thu Aug 17 22:37:38 UTC 2006


Tofig Suleymanov wrote this message on Thu, Aug 17, 2006 at 17:10 +0500:
> is there anybody to explain why do we have infinite loop inside of
> USB_ATTACH_SETUP macros inside of usb_port.h ? How does his loop gets
> escaped when we use it in some usb driver ?
> 
> #define USB_ATTACH_SETUP \
>         do { \
>                 sc->sc_dev = self; \
>                 device_set_desc_copy(self, devinfo); \
>                 device_printf(self, "%s\n", devinfo); \
>         } while (0);

The real bug here is the extra ; after the while(0) part... because
if you use it as such:
	if (case)
		USB_ATTACH_SETUP;
	else
		somethingelse;

you will get a compile error due to the double semicolon...

In cases like this, it is also common to have parens after the macro
name so that it looks like a function, and not a simple expresion.

-- 
  John-Mark Gurney				Voice: +1 415 225 5579

     "All that I will do, has been done, All that I have, has not."


More information about the freebsd-usb mailing list