From owner-freebsd-current Sat Mar 14 01:13:54 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id BAA07578 for freebsd-current-outgoing; Sat, 14 Mar 1998 01:13:54 -0800 (PST) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from smtp03.primenet.com (smtp03.primenet.com [206.165.6.133]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id BAA07572; Sat, 14 Mar 1998 01:13:52 -0800 (PST) (envelope-from tlambert@usr08.primenet.com) Received: (from daemon@localhost) by smtp03.primenet.com (8.8.8/8.8.8) id CAA23921; Sat, 14 Mar 1998 02:13:49 -0700 (MST) Received: from usr08.primenet.com(206.165.6.208) via SMTP by smtp03.primenet.com, id smtpd023896; Sat Mar 14 02:13:39 1998 Received: (from tlambert@localhost) by usr08.primenet.com (8.8.5/8.8.5) id CAA18517; Sat, 14 Mar 1998 02:13:36 -0700 (MST) From: Terry Lambert Message-Id: <199803140913.CAA18517@usr08.primenet.com> Subject: Re: A question about sys/sys/queue.h To: jmb@FreeBSD.ORG (Jonathan M. Bresler) Date: Sat, 14 Mar 1998 09:13:36 +0000 (GMT) Cc: shimon@simon-shapiro.org, freebsd-current@FreeBSD.ORG In-Reply-To: <199803130339.TAA10294@hub.freebsd.org> from "Jonathan M. Bresler" at Mar 12, 98 07:39:39 pm X-Mailer: ELM [version 2.4 PL25] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > #define FOO do { ... } while(0) > > > > I thought these are the same... > > > > the difference lies in how you use them. > in the first case one writes "FOO" > in the second "FOO;" > ^ > make a macro act more like a statement. > > imagine the code around the macro > rather then the macro itself. > > first saw this in _C_traps_and_pitfalls_ > by andrew koenig (sp?) One problem with this approach is register optimization triggered by loop_start/loop_stop marking for possible unrolling by the optimizer. For example, if you reference a variable which is volaatile (but not marked volatile) outside a loop, or using an if/goto to implement the loop instead of a loop construct, you won't get the register optimization. This will potentially case (admittedly "incorrect" according to ANSI) code that was working to now break. I had this problem one time; it was bugger-all to track down (before you ask, no, it was not my incorrect non-marking of the variable; I was maintaining ssomeone else's code). 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-current" in the body of the message