* Re: A little explanation needed
2002-12-22 5:36 A little explanation needed Joshua Stewart
@ 2002-12-22 5:35 ` Greg KH
2002-12-22 21:07 ` Joshua Stewart
2002-12-22 20:12 ` DervishD
1 sibling, 1 reply; 4+ messages in thread
From: Greg KH @ 2002-12-22 5:35 UTC (permalink / raw
To: Joshua Stewart; +Cc: linux-kernel
On Sun, Dec 22, 2002 at 12:36:32AM -0500, Joshua Stewart wrote:
>
> In otherwords, what's the use of a do{X}while(0) "loop" instead of just
> X. I'm not the world's best trained C programmer, so forgive me if I
> sound stupid.
http://www.kernelnewbies.org/faq/index.php3#dowhile
Hope that helps,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* A little explanation needed
@ 2002-12-22 5:36 Joshua Stewart
2002-12-22 5:35 ` Greg KH
2002-12-22 20:12 ` DervishD
0 siblings, 2 replies; 4+ messages in thread
From: Joshua Stewart @ 2002-12-22 5:36 UTC (permalink / raw
To: linux-kernel
Can anyone explain the purpose of this #define...
#define __cpu_raise_softirq(cpu, nr) do { softirq_pending(cpu) |= 1UL <<
(nr); } while (0) // from interrupt.h
...versus the more "plain"...
#define __cpu_raise_softirq(cpu,nr) softirq_pending(cpu |= 1UL << (nr).
In otherwords, what's the use of a do{X}while(0) "loop" instead of just
X. I'm not the world's best trained C programmer, so forgive me if I
sound stupid.
Josh
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: A little explanation needed
2002-12-22 5:36 A little explanation needed Joshua Stewart
2002-12-22 5:35 ` Greg KH
@ 2002-12-22 20:12 ` DervishD
1 sibling, 0 replies; 4+ messages in thread
From: DervishD @ 2002-12-22 20:12 UTC (permalink / raw
To: Joshua Stewart; +Cc: linux-kernel
Hi Joshua :)
> In otherwords, what's the use of a do{X}while(0) "loop" instead of
> just X. I'm not the world's best trained C programmer, so forgive
> me if I sound stupid.
First, you do not sound stupid at all.
Second. The do...while use in macros is to avoid the 'swallow
semicolon' effect ;)) In other words, it makes the entire macro
appear as a single statement. This avoids problems with 'else'
constructs with macros that expand to multiple statements.
Someplace in the GNU cpp documentation you can find a far better
explanation of this effect and why the do...while helps (it makes the
macro a single statement...).
Hope that helps :)
Raúl
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: A little explanation needed
2002-12-22 5:35 ` Greg KH
@ 2002-12-22 21:07 ` Joshua Stewart
0 siblings, 0 replies; 4+ messages in thread
From: Joshua Stewart @ 2002-12-22 21:07 UTC (permalink / raw
To: Greg KH; +Cc: linux-kernel
Thanks for the help. It all makes perfect sense after thinking about it
from a preprecessor point of view. I'm just not used to using so many
macros and so I don't realize all the implications of preprocessing
quite yet. But, I'm learning.
Josh
On Sun, 2002-12-22 at 00:35, Greg KH wrote:
> On Sun, Dec 22, 2002 at 12:36:32AM -0500, Joshua Stewart wrote:
> >
> > In otherwords, what's the use of a do{X}while(0) "loop" instead of just
> > X. I'm not the world's best trained C programmer, so forgive me if I
> > sound stupid.
>
> http://www.kernelnewbies.org/faq/index.php3#dowhile
>
> Hope that helps,
>
> greg k-h
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-12-22 20:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-12-22 5:36 A little explanation needed Joshua Stewart
2002-12-22 5:35 ` Greg KH
2002-12-22 21:07 ` Joshua Stewart
2002-12-22 20:12 ` DervishD
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.