Re: why do we use while (0)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 < asahlot@xxxxxxxxx> 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)
 
 
My question is why do we use a loop when we actually know that it is not going to execute more than once? Cannot we simply do -
 
#define INIT_LIST_HEAD(ptr)    {(ptr)->next = (ptr); (ptr)->prev = (ptr)}
 
Do we get some kind of optimization by using while (0)?
 
 
Thanks

 



--
Dinesh Bansal
The Law of Win says, "Let's not do it your way or my way; let's do it the best way."

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux