AW: [mpls-linux-general] coding style of macros
Status: Beta
Brought to you by:
jleu
|
From: Georg K. <gk...@gi...> - 2003-02-14 12:24:16
|
Hi,
>
> > here's a macro i came across in the mpls linux code
> >
> > define INIT_LIST_HEAD(ptr) do { \
> > (ptr)->next = (ptr); (ptr)->prev = (ptr); \
> > } while (0)
> >
> > at the risk of sounding prude,
> > why is it that the initialization statements were enclosed in braces with a
> > while(0) ?
> >
> > couldn't it be simply written as
> >
> > define INIT_LIST_HEAD(ptr) (ptr)->next = (ptr); (ptr)->prev = (ptr);
>
> Think to something like that:
>
> if (ptr != NULL)
> INIT_LIST_HEAD(ptr);
>
> Without the do { ... }while(0) statement, the second instruction would
> be outside the "if".
That's true, but would just braces { .. } be sufficient for that purpose?
Georg
|