All of lore.kernel.org
 help / color / mirror / Atom feed
From: Crutcher Dunnavant <crutcher@datastacks.com>
To: linux-kernel@vger.kernel.org
Subject: Re: fake loop
Date: Fri, 3 Aug 2001 12:13:28 -0400	[thread overview]
Message-ID: <20010803121328.A14741@mueller.datastacks.com> (raw)
In-Reply-To: <20010803155735.18620.qmail@nwcst31f.netaddress.usa.net>
In-Reply-To: <20010803155735.18620.qmail@nwcst31f.netaddress.usa.net>; from ailinykh@usa.net on Fri, Aug 03, 2001 at 09:57:34AM -0600

++ 03/08/01 09:57 -0600 - Andrey Ilinykh:
> Hi!
> Very often I see in kernel such code as
> do {
>   dosomthing();
> } while(0);

This is a fake function. Macros often use this to give themselves an environment
to allocate stack variables in. Example:

 #define swap(A, B) \
 { \
	int C; \
	C = (A); (A) = (B); (B) = C; \
 } while(0)

swap will now act almost exactly like a function. Please note that this macro
does NOT have a semicolon on the end, as that would cause bad things if I did:

 if (test)
	swap(a,b);
 else
	do_something();

> or even
> #define prepare_to_switch()     do { } while(0)

This is most often found in situations where a code block becomes trivial when
a config option is turned off. The spinlock functions mostly become this when
SMP is not turned on, so they get optimized out of the code.

-- 
Crutcher        <crutcher@datastacks.com>
GCS d--- s+:>+:- a-- C++++$ UL++++$ L+++$>++++ !E PS+++ PE Y+ PGP+>++++
    R-(+++) !tv(+++) b+(++++) G+ e>++++ h+>++ r* y+>*$

  parent reply	other threads:[~2001-08-03 16:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-03 15:57 fake loop Andrey Ilinykh
2001-08-03 16:07 ` Thomas Pornin
2001-08-03 16:11 ` Martin Mačok
2001-08-03 16:13 ` Crutcher Dunnavant [this message]
2001-08-03 16:25 ` Mike Frisch
2001-08-03 16:44 ` Richard B. Johnson
2001-08-04  0:13   ` J . A . Magallon
2001-08-04 18:47     ` Thomas Pornin

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=20010803121328.A14741@mueller.datastacks.com \
    --to=crutcher@datastacks.com \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.