Date: Thu, 17 Aug 2006 15:37:16 -0700 From: John-Mark Gurney <gurney_j@resnet.uoregon.edu> To: Tofig Suleymanov <tofik@oxygen.az> Cc: usb@freebsd.org Subject: Re: USB_ATTACH_SETUP macros question Message-ID: <20060817223716.GW99774@funkthat.com> In-Reply-To: <35069.85.132.32.38.1155816624.squirrel@85.132.32.38> References: <35069.85.132.32.38.1155816624.squirrel@85.132.32.38>
index | next in thread | previous in thread | raw e-mail
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."
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060817223716.GW99774>
