USB_ATTACH_SETUP macros question

Julian Elischer julian at elischer.org
Thu Aug 17 22:55:20 UTC 2006


John-Mark Gurney wrote:

>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...
>  
>

yes style(9) specifies this form of macro should NOT have the 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.
>  
>
yes



More information about the freebsd-usb mailing list