sahlot arvind wrote:
Recently I started looking into linux kernel and trying to understand the
code.
I am working with linux-2.6.9.
in file include/llinux/list.h - I found something like this.
#define INIT_LIST_HEAD(ptr) do { \
(ptr)-next = (ptr); (ptr)-prev = (ptr); \
} while (0)
One more reason could be, by using do-while(0) thingy, one could use
'break' statement at any place just to come out of the macro at once.
Thanks.
Anupam Kapoor wrote:
sahlot arvind [EMAIL PROTECTED] wrote:
,
| Recently I started looking into linux kernel and trying to understand
| the
The intent is just to enclose the code of the macro in a block, so that if
you were to place this macro after an if() statement, and the macro was
multi-line, it would not break things.
eg.
#define crazy(a, b) \
a = b; \
b = a;
if(\*something*\)
crazy(a,b)
Look at this carefully, which
Recently I started looking into linux kernel and trying to understand the
code.
I am working with linux-2.6.9.
in file include/llinux/list.h - I found something like this.
#define INIT_LIST_HEAD(ptr) do { \
(ptr)-next = (ptr); (ptr)-prev = (ptr); \
} while (0)
My question is why do we
Its not because of optimization. This is done to convert a multiline
expression into a single line expression so that it does not break if-else
functionality.
On Dec 26, 2007 11:44 AM, sahlot arvind [EMAIL PROTECTED] wrote:
Recently I started looking into linux kernel and trying to
I tried this -
-
struct list_head {
struct list_head *next, *prev;
};
#define INIT_LIST_HEAD(ptr){(ptr)-next = (ptr); (ptr)-prev = (ptr);}
int main ()
{
int i;
struct list_head mylist;
struct list_head *ptr = mylist;
printf (hi\n);
if
Yes I get an error in this code -
-
struct list_head {
struct list_head *next, *prev;
};
#define INIT_LIST_HEAD(ptr){(ptr)-next = (ptr); (ptr)-prev = (ptr);}
int main ()
{
int i;
struct list_head mylist;
struct list_head *ptr = mylist;
sahlot arvind wrote:
Yes I get an error in this code -
-
struct list_head {
struct list_head *next, *prev;
};
#define INIT_LIST_HEAD(ptr){(ptr)-next = (ptr); (ptr)-prev = (ptr);}
int main ()
{
int i;
struct list_head mylist;
struct
sahlot arvind [EMAIL PROTECTED] wrote:
,
| Recently I started looking into linux kernel and trying to understand
| the code. I am working with linux-2.6.9. in file
| include/llinux/list.h - I found something like this.
|
| #define INIT_LIST_HEAD(ptr) do { \
| (ptr)-next = (ptr);