From: Mikael Pettersson <mikpe@csd.uu.se>
To: romieu@cogenit.fr, support@promise.com.tw
Cc: hanky@promise.com.tw, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] 2.4.19-rc2-ac2 pdc202xx.c update
Date: Tue, 23 Jul 2002 12:49:56 +0200 (MET DST) [thread overview]
Message-ID: <200207231049.MAA16464@harpo.it.uu.se> (raw)
On Tue, 23 Jul 2002 09:19:15 +0200, Francois Romieu wrote:
>support <support@promise.com.tw> :
>> We think there is no problems, Acturally it is
>>
>> if (speed == XFER_UDMA_2) {
>> OUT_BYTE((thold + adj), indexreg);
>> OUT_BYTE((IN_BYTE(datareg) & 0x7f), datareg);
>> }
>>
>> So,
>> if (speed == XFER_UDMA_2)
>> set_2regs(thold, (IN_BYTE(datareg) & 0x7f));
The problem is a common one for complex statement-like macros.
You have a macro M consisting of (in this case) two statements
S1 and S2: "#define M S1; S2". Now consider what happens when
M is used in non-block context, i.e. not as a top-level
statement between { and } but rather in e.g. the true branch
of an if-statement:
if (condition)
M;
which after preprocessing becomes
if (condition)
S1; S2;
However, indentation doesn't matter, only grouping does, so this
USE of the macro really is
if (condition)
S1;
S2;
Now do you see? The macro body was broken up, and the second statement
is now executed unconditionally.
The traditional approach is to write the body of a complex macro as a
do { ... } while(0) statement (i.e. #define M do { S1; S2; } while(0))
since this turns the macro body into a single unbreakable statement
which is safe to use in any context where a statement may occur.
Simply wrapping the macro body with a pair of braces { } doesn't work
in all contexts; the do{...}while(0) idiom does.
/Mikael
next reply other threads:[~2002-07-23 10:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-23 10:49 Mikael Pettersson [this message]
[not found] <01b801c22f0b$c02cc360$47cba8c0@promise.com.tw>
2002-07-22 3:16 ` support
2002-07-22 6:35 ` Francois Romieu
2002-07-23 1:05 ` support
2002-07-23 7:19 ` Francois Romieu
2002-07-23 17:08 ` Michal Jaegermann
-- strict thread matches above, loose matches on Subject: below --
2002-07-19 9:09 support
2002-07-19 9:52 ` Giro
2002-07-19 9:56 ` Giro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200207231049.MAA16464@harpo.it.uu.se \
--to=mikpe@csd.uu.se \
--cc=hanky@promise.com.tw \
--cc=linux-kernel@vger.kernel.org \
--cc=romieu@cogenit.fr \
--cc=support@promise.com.tw \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®