On Monday 09 May 2005 15:33, Muli Ben-Yehuda wrote:
> On Mon, May 09, 2005 at 03:13:11PM +0300, Leonid Podolny wrote:
> 
> > This macro expands to another one (at include/linux/sunrpc/cache.h) ,
> > which, in turn, expands to yet another one. I'm yet to figure out the
> > whole mechanism, but this is really dirty. :)
> 
> vomit inducing is a better word. Submit a patch to unroll these
> suckers, mayeb the maintainers would act sanely and take it (not
> counting on it though).

Talking about macros and vomiting, here is a partial (little
modified) snippet:

#define D_(op,d,txt)    \
           [ FOO_##op ] {       \
                   .opcode = FOO_##op, \
                   .dir = d, \
                   .name = #op, \
                   .desc = txt \
           }

static foo_commands_t foo_commands[] = {
        D_(RING,   LEFT,  "Start/Stop Ring"),
        D_(STATUS, RIGHT, "Status Detect"),
                ... assume a long list ...
};

#undef D_

Now I'll admit this was written by me (kernel code, not yet
distributed). These sort of ugliness is justified IMO only when
the alternative is uglier. In this case, you'd need to initialize
the array and assure that each opcode (which comes from a separate
enum BTW), falls into its index and contains the correct name --
and remember that repetitions are a big no-no in vomit-land.

BTW: I think it's the same argument about the massive use of
     goto's in the kernel -- they are used when the alternative
     is uglier.

Cheers,

-- 
Oron Peled                             Voice/Fax: +972-4-8228492
[EMAIL PROTECTED]                  http://www.actcom.co.il/~oron
ICQ UIN: 16527398

"Software is like Entropy: it's hard to grasp, weighs nothing and
obeys the  Second Law of Thermodynamics, i.e. it always increases" 
        -- Norman Augustine 

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to