From owner-freebsd-chat Sat Feb 26 5:47:18 2000 Delivered-To: freebsd-chat@freebsd.org Received: from scientia.demon.co.uk (scientia.demon.co.uk [212.228.14.13]) by hub.freebsd.org (Postfix) with ESMTP id 109E637BC8B for ; Sat, 26 Feb 2000 05:46:47 -0800 (PST) (envelope-from ben@scientia.demon.co.uk) Received: from strontium.scientia.demon.co.uk ([192.168.91.36] ident=exim) by scientia.demon.co.uk with esmtp (Exim 3.12 #1) id 12Ogsn-000CKQ-00; Sat, 26 Feb 2000 13:03:41 +0000 Received: (from ben) by strontium.scientia.demon.co.uk (Exim 3.12 #7) id 12Ogsn-000PkQ-00; Sat, 26 Feb 2000 13:03:41 +0000 Date: Sat, 26 Feb 2000 13:03:41 +0000 From: Ben Smithurst To: Alfred Perlstein Cc: cjclark@home.com, Marco Molteni , freebsd-chat@FreeBSD.ORG Subject: Re: how to do this C preprocessor trick? Message-ID: <20000226130341.B98536@strontium.scientia.demon.co.uk> References: <20000225182432.A5017@sofia.csl.sri.com> <20000226001121.A20702@cc942873-a.ewndsr1.nj.home.com> <20000225214616.U21720@fw.wintelcom.net> <20000226003741.C20702@cc942873-a.ewndsr1.nj.home.com> <20000225234909.W21720@fw.wintelcom.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20000225234909.W21720@fw.wintelcom.net> Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org Alfred Perlstein wrote: > * Crist J. Clark [000225 22:02] wrote: >> >> Why a, >> >> do { } while(0) >> >> Rather than just, >> >> { } > > I really don't remeber offhand, I know a lot of macros in FreeBSD > are moved from > > #define foo { bar; baz; } > > to > > #define foo do{ bar; baz; }while(0) with the original #define, if (some_condition) foo; else bar(); would expand to, if (some_condition) { bar; baz; }; else bar(); That is a syntax error (extra semicolon before "else"). I used to use the form without do/while until this bit me. :-) With the second form, well you can work it out, and the expanded code is perfectly legal. -- Ben Smithurst / ben@scientia.demon.co.uk / PGP: 0x99392F7D To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-chat" in the body of the message