lkml.org 
[lkml]   [2002]   [Dec]   [22]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
DateSun, 22 Dec 2002 21:12:23 +0100
FromDervishD <>
SubjectRe: A little explanation needed
    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
-
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/

\
 
 \ /
  Last update: 2005-03-22 12:31    [from the cache]
©2003-2008