Re: asm/unistd.h

From: J . A . Magallon (jamagallon@able.es)
Date: Thu Apr 05 2001 - 12:38:40 EST


On 04.05 Andreas Schwab wrote:
>
> Try this and watch your compiler complaining:
>
> #define foo() { }
> #define bar() do { } while (0)
> void mumble ()
> {
> if (1) foo(); else bar();
> if (2) bar(); else foo();
> }
>

Perhaps it is time to USE gcc, yet the kernel can be built only with gcc.
IE, use statement expressions.

Try this:

#define foo() ({ })
#define bar() do { } while (0)
void mumble ()
{
        if (1) foo(); else bar();
        if (2) bar(); else foo();
}

and see you compiler shutup.
You can even declare vars inside the ({ ... }) block,
so all the

#define bar(x) do { use_1(x); use_2(x); } while (0)

could be written like:

#define bar(x) ({ use_1(x); use_2(x); })

Even you can use <typeof>:

#define swap(a,b) \
({ typeof(a) tmp = a; \
   a = b; \
   b = tmp; \
})

int main()
{
        int a,b;
        double c,d;
        
        swap(a,b);
        swap(c,d);
}

Its correct in egcs-1.1.2 and up, so it is safe for use in kernel 2.4.
Do not know if previuous gcc eats it up.

-- 
J.A. Magallon                                          #  Let the source
mailto:jamagallon@able.es                              #  be with you, Luke... 

Linux werewolf 2.4.3-ac3 #1 SMP Thu Apr 5 00:28:45 CEST 2001 i686

- 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/



This archive was generated by hypermail 2b29 : Sat Apr 07 2001 - 21:00:17 EST