From owner-freebsd-usb@FreeBSD.ORG Fri Aug 18 06:38:05 2006 Return-Path: X-Original-To: usb@freebsd.org Delivered-To: freebsd-usb@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 059A416A4DE for ; Fri, 18 Aug 2006 06:38:05 +0000 (UTC) (envelope-from tofik@oxygen.az) Received: from mail.oxygen.az (mail.oxygen.az [212.47.128.37]) by mx1.FreeBSD.org (Postfix) with ESMTP id 57DD343D49 for ; Fri, 18 Aug 2006 06:38:04 +0000 (GMT) (envelope-from tofik@oxygen.az) Received: from mail.oxygen.az (localhost [127.0.0.1]) by mail.oxygen.az (Postfix) with ESMTP id 3A76413C8D; Fri, 18 Aug 2006 11:38:02 +0500 (AZST) X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on earth.oxygen.az X-Spam-Level: X-Spam-Status: No, score=-3.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.0 Received: from webmail.oxygen.az (mail.oxygen.az [212.47.128.37]) by mail.oxygen.az (Postfix) with ESMTP id 8F5FE13BC6; Fri, 18 Aug 2006 11:38:01 +0500 (AZST) Received: from 85.132.32.38 (proxying for 85.132.14.38) (SquirrelMail authenticated user secnews); by webmail.oxygen.az with HTTP; Fri, 18 Aug 2006 11:38:01 +0500 (AZST) Message-ID: <38357.85.132.32.38.1155883103.squirrel@85.132.32.38> In-Reply-To: <20060817.091700.-432836888.imp@bsdimp.com> References: <35069.85.132.32.38.1155816624.squirrel@85.132.32.38> <20060817121307.GA804@gremlin.foo.is> <35146.85.132.32.38.1155817977.squirrel@85.132.32.38> <20060817.091700.-432836888.imp@bsdimp.com> Date: Fri, 18 Aug 2006 11:38:01 +0500 (AZST) From: "Tofig Suleymanov" To: "M. Warner Losh" User-Agent: SquirrelMail/1.4.3a X-Mailer: SquirrelMail/1.4.3a MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Virus-Scanned: -= ClamAV =- Cc: usb@freebsd.org Subject: Re: USB_ATTACH_SETUP macros question X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: tofik@oxygen.az List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Aug 2006 06:38:05 -0000 > In message: <35146.85.132.32.38.1155817977.squirrel@85.132.32.38> > "Tofig Suleymanov" writes: > : > : > On Thu, Aug 17, 2006 at 05:10:02PM +0500, Tofig Suleymanov wrote: > : >> Hello hackers, > : >> > : >> 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); > : >> > : >> Thank you ! > : >> > : >> Tofig Suleymanov > : >> > : > This isn't an infinite loop, in fact it will never be executed. > : > > : > Baldur > : > > : > : Made a little test which shows that this code is going to be executed > only > : once.How did i miss that :) Now the other question comes next: > : Why don not we use just: > : #define USB_ATTACH_SETUP \ > : sc->sc_dev = self; \ > : device_set_desc_copy(self, devinfo); \ > : device_printf(self, "%s\n", devinfo); > > Actually, it is neither an infinite loop, nor is it a never execute > loop. > > the do { ... } while (0); is a way to make a macro lexically identical > to a function call so that if you do something like: > > if (blah) > USB_ATTACH_SETUP; > > it will parse as you intended. Which is to say it will parse exactly > the same as: > > if (blah) { > USB_ATTACH_STUP; > } > > Without the do while construct, your example would cause different > results in the latter and former cases. > > Warner > _______________________________________________ > freebsd-usb@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-usb > To unsubscribe, send any mail to "freebsd-usb-unsubscribe@freebsd.org" > > Thank you, now it is clear to me. Sincerely, Tofig Suleymanov