From owner-freebsd-current Fri Mar 13 08:53:43 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id IAA25447 for freebsd-current-outgoing; Fri, 13 Mar 1998 08:53:43 -0800 (PST) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from mailout05.btx.dtag.de (mailout05.btx.dtag.de [194.25.2.153]) by hub.freebsd.org (8.8.8/8.8.8) with SMTP id IAA25438 for ; Fri, 13 Mar 1998 08:53:37 -0800 (PST) (envelope-from lennartz.electronic@t-online.de) Received: from fwd09.btx.dtag.de (fwd09.btx.dtag.de [194.25.2.169]) by mailout05.btx.dtag.de with smtp id 0yDXgT-0000g2-00; Fri, 13 Mar 1998 17:51:49 +0100 Received: from fw.tue.le (0707193550-0001(btxid)@[193.159.35.17]) by fwd09.btx.dtag.de with smtp id ; Fri, 13 Mar 1998 17:51:35 +0100 Received: from mezcal.tue.le (mezcal.tue.le [192.168.201.20]) by fw.tue.le (8.8.8/8.8.8) with ESMTP id RAA01742 for ; Fri, 13 Mar 1998 17:49:43 +0100 (CET) (envelope-from thz@mezcal.tue.le) Received: (from thz@localhost) by mezcal.tue.le (8.8.5/8.8.8) id RAA00952; Fri, 13 Mar 1998 17:49:43 +0100 (MET) (envelope-from thz) Message-ID: <19980313174942.53822@tue.le> Date: Fri, 13 Mar 1998 17:49:42 +0100 To: freebsd-current@FreeBSD.ORG Subject: Re: A question about sys/sys/queue.h References: <19980313121330.54903@follo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89.1i In-Reply-To: <19980313121330.54903@follo.net>; from Eivind Eklund on Fri, Mar 13, 1998 at 12:13:30PM +0100 X-Sender: 0707193550-0001@t-online.de From: lennartz.electronic@t-online.de (Thomas Zenker) Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Fri, Mar 13, 1998 at 12:13:30PM +0100, Eivind Eklund wrote: > On Thu, Mar 12, 1998 at 07:17:45PM -0800, Simon Shapiro wrote: > > Why was the definition of some macros changed > > from: > > > > #define FOO(a) { ... } > > > > to: > > > > #define FOO(a) do { ... } while(0) > > > > I thought these are the same... > > Imagine these used in a dual if () statement: > > if (bar) > if (baz) > FOO(1); > else > printf ("You loose!\n"); > > With the former, you get something that (with proper indentation) map > as > > if (bar) > if (baz) > { ... }; > else > printf ("You loose!\n"); > > while with the do {...} while (0) trick, you get > > if (bar) > if (baz) > do { ... } while(0); > else > printf ("You loose!\n"); > It will not compile anyway. The version w/ "{ ... };" is syntactically incorrect, because there are two statements after the if, leaving the else w/o partner. if (bar) if (baz) { ... } /* compound_statement */ ; /* empty but existing statment! */ else /* else without matching if! */ ... while the second version "do { ... } while (0);" still is a simple statement. -- Thomas Zenker at work thz@lennartz-electronic.de private thz@tuebingen.netsurf.de To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message