reason for code like this: "do { something } while (0)"

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

 



Hi,

I'm asking a pretty amateur question.

I've come accross code like this huge number of times in the kernel:

#define __set_task_state(tsk, state_value)              \
       do { (tsk)->state = (state_value); } while (0)

What is the reason to use do while loop if it is only meant to be
executed just once? Why not a simple:

#define __set_task_state(tsk, state_value)              \
       { (tsk)->state = (state_value); }

TIA,

Rajat

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[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