lkml.org 
[lkml]   [2005]   [Jun]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] Dynamic tick for x86 version 050602-2
Date
On Jun 10, 2005, at 05:15:15, Pavel Machek wrote:
> Hi!
>>> do {} while (0)
>>>
>>> , else you are preparing trap for someone.
>>>
>>
>> Can you please explain what the difference between these two are?
>> Some compiler version specific thing?
>>
>
> It took me quite some remembering. Problem is that with your macros,
> someone can write
>
> dyn_tick_reprogram_timer()
> printk();
>
> [notice missing ; at first line], and still get it compile. If you
> replace {} with do {} while (0), he'll get compile error as he should.

Actually, the real reason is for something like this:

#define myfunc1() {}
#define myfunc2() {}

if (a && b) myfunc1();
else myfunc2();

This would be translated as:

if (a && b) {};
else {};

Which would generate a syntax error:
zeus:~ kyle$ gcc -c `y -e .c` -o tmp.o <<'EOF'
> #define myfunc1() {}
> #define myfunc2() {}
> void x() {
> int a = 0, b = 1;
> if (a && b) myfunc1();
> else myfunc2();
> }
> EOF
/tmp/y.c8F08d.c: In function ‘x’:
/tmp/y.c8F08d.c:4: error: parse error before "else"

Cheers,
Kyle Moffett



-
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-06-11 20:04    [W:0.085 / U:0.036 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site