From owner-freebsd-current Fri Mar 13 03:13:43 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id DAA08144 for freebsd-current-outgoing; Fri, 13 Mar 1998 03:13:43 -0800 (PST) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from ns1.yes.no (ns1.yes.no [195.119.24.10]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id DAA08129 for ; Fri, 13 Mar 1998 03:13:38 -0800 (PST) (envelope-from eivind@bitbox.follo.net) Received: from bitbox.follo.net (bitbox.follo.net [194.198.43.36]) by ns1.yes.no (8.8.7/8.8.7) with ESMTP id LAA20224; Fri, 13 Mar 1998 11:13:32 GMT Received: (from eivind@localhost) by bitbox.follo.net (8.8.6/8.8.6) id MAA06896; Fri, 13 Mar 1998 12:13:30 +0100 (MET) Message-ID: <19980313121330.54903@follo.net> Date: Fri, 13 Mar 1998 12:13:30 +0100 From: Eivind Eklund To: shimon@simon-shapiro.org, freebsd-current@FreeBSD.ORG Subject: Re: A question about sys/sys/queue.h References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89.1i In-Reply-To: ; from Simon Shapiro on Thu, Mar 12, 1998 at 07:17:45PM -0800 Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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"); For any onlookerss: You can't get the correct binding with if () tricks, BTW. Stick with the good old "do { ... } while(0)" Eivind. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message