Date: Sat, 14 Mar 1998 09:13:36 +0000 (GMT) From: Terry Lambert <tlambert@primenet.com> To: jmb@FreeBSD.ORG (Jonathan M. Bresler) Cc: shimon@simon-shapiro.org, freebsd-current@FreeBSD.ORG Subject: Re: A question about sys/sys/queue.h Message-ID: <199803140913.CAA18517@usr08.primenet.com> In-Reply-To: <199803130339.TAA10294@hub.freebsd.org> from "Jonathan M. Bresler" at Mar 12, 98 07:39:39 pm
next in thread | previous in thread | raw e-mail | index | archive | help
> > #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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199803140913.CAA18517>
