DragonFly BSD
DragonFly kernel List (threaded) for 2006-09
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: Batch/At (if it wasn't broken, no worries I broke it :-) )


From: David Cuthbert <dacut@xxxxxxxxx>
Date: Wed, 06 Sep 2006 19:32:28 -0700

Diane Bruce wrote:
I hate macro definitions with a passion. They obsfuscate the code
badly, have too many side effects, are harder to debug.
Use nice normal functions.

There are right and wrong ways to use macros. I often find myself writing a macro to translate between an enum and its string equivalent, e.g.:


enum ErrorStatus {
    esNone,
    esFailed,
    esMaybe
};

char const *ansToString(ErrorStatus es)
{
    switch (es) {
#define HANDLE_ERROR_STATUS(n) case n: return #n
        HANDLE_ERROR_STATUS(esNone);
        HANDLE_ERROR_STATUS(esFailed);
        HANDLE_ERROR_STATUS(esMaybe);
#undef HANDLE_ERROR_STATUS
    }
}


This could just be the domain I work in, though. I do a lot with scripting languages and interfacing legacy code to talk to new services over the wire.




[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]