From owner-freebsd-chat Tue Mar 7 14:22:31 2000 Delivered-To: freebsd-chat@freebsd.org Received: from smtp03.primenet.com (smtp03.primenet.com [206.165.6.133]) by hub.freebsd.org (Postfix) with ESMTP id 760F837C14C for ; Tue, 7 Mar 2000 14:22:26 -0800 (PST) (envelope-from tlambert@usr09.primenet.com) Received: (from daemon@localhost) by smtp03.primenet.com (8.9.3/8.9.3) id PAA02802; Tue, 7 Mar 2000 15:22:03 -0700 (MST) Received: from usr09.primenet.com(206.165.6.209) via SMTP by smtp03.primenet.com, id smtpdAAA1maytf; Tue Mar 7 15:21:50 2000 Received: (from tlambert@localhost) by usr09.primenet.com (8.8.5/8.8.5) id PAA01371; Tue, 7 Mar 2000 15:22:05 -0700 (MST) From: Terry Lambert Message-Id: <200003072222.PAA01371@usr09.primenet.com> Subject: Re: how to do this C preprocessor trick? To: cjclark@home.com Date: Tue, 7 Mar 2000 22:22:04 +0000 (GMT) Cc: bright@wintelcom.net (Alfred Perlstein), molter@csl.sri.com (Marco Molteni), freebsd-chat@FreeBSD.ORG In-Reply-To: <20000226003741.C20702@cc942873-a.ewndsr1.nj.home.com> from "Crist J. Clark" at Feb 26, 2000 12:37:41 AM X-Mailer: ELM [version 2.5 PL2] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org > Why a, > > do { } while(0) > > Rather than just, > > { } To make it anal. It requires a semicolon in the first case. In the second case, it can be expanded, e.g. in an "if/else" as if( x) { }; else other_stuff... as opposed to: if( x) do { } while(0); else other_stuff... Basically, it lets people be lazy about semicolongs and about making macros upper case and functions lower case, so you can tell if you are getting a function call overhead or an inline preprocessor expansion of a macro. I personally think it's lazy coding, and leads to bad practices, like lowercase macro names or upper case function names becoming an acceptable practice. For blocks of code, it makes it real easy to include more than the 10 lines of code allowed by the (L)GPL by innocently including a header file, and not realizing that it's a block macro instead of a simple macro, or that it's a macro instead of a library function, etc.. Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-chat" in the body of the message