Date: Tue, 7 Mar 2000 22:22:04 +0000 (GMT) From: Terry Lambert <tlambert@primenet.com> To: cjclark@home.com Cc: bright@wintelcom.net (Alfred Perlstein), molter@csl.sri.com (Marco Molteni), freebsd-chat@FreeBSD.ORG Subject: Re: how to do this C preprocessor trick? Message-ID: <200003072222.PAA01371@usr09.primenet.com> In-Reply-To: <20000226003741.C20702@cc942873-a.ewndsr1.nj.home.com> from "Crist J. Clark" at Feb 26, 2000 12:37:41 AM
next in thread | previous in thread | raw e-mail | index | archive | help
> Why a, > > do { <stuff> } while(0) > > Rather than just, > > { <stuff> } 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) { <stuff> }; else other_stuff... as opposed to: if( x) do { <stuff> } 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200003072222.PAA01371>