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

David Cuthbert dacut at kanga.org
Wed Sep 6 19:32:28 PDT 2006


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.





More information about the Kernel mailing list