Re: [PATCH] Dynamic tick for x86 version 050602-2

Kyle Moffett
2005-06-11T18:00:13Z

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