Re: Why do { // do something ; } while (0); ?

2012-12-13 Thread Adel Qodmani
On Thu, Dec 13, 2012 at 10:55 AM, Shraddha Kamat  wrote:

> I notice
>
> do {
>// do something 1 ;
>// do something 2 ;
>...
> } while (0);
>
> being used everywhere in the kernel code
> I just can't guess of any use of this other
> than executing couple of C statements together ?
>
> Is there any special purpose of doing this ??
> Sorry of such a silly question - I am just trying
> to learn kernel hacking basics.
>
> -- Shraddha
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


http://stackoverflow.com/questions/257418/do-while-0-what-is-it-good-for

This link gives you a pretty good answer.
The basic rational behind using such a construct is when you want to a
define a multi-line macro.
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Why do { // do something ; } while (0); ?

2012-12-13 Thread Adam Lee
On Thu, Dec 13, 2012 at 02:25:37PM +0530, Shraddha Kamat wrote:
> I notice
>  
> do {
>// do something 1 ; 
>// do something 2 ;
>...
> } while (0); 
> 
> being used everywhere in the kernel code
> I just can't guess of any use of this other 
> than executing couple of C statements together ?
> 
> Is there any special purpose of doing this ?? 
> Sorry of such a silly question - I am just trying 
> to learn kernel hacking basics.

http://kernelnewbies.org/FAQ/DoWhile0

-- 
Regards,
Adam Lee
http://adam8157.info

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies