

Code generation with X-Macros in C - benhoyt
http://blog.brush.co.nz/2009/08/xmacros/

======
DenisM
I have a better idea that does not require an extra include file:

    
    
      #define TASK_STATUS_ENUM(VALUE) ts##VALUE
      #define TASK_STATUS_ENUM_COMA(VALUE) TASK_STATUS_ENUM(VALUE) ,
    
      #define TASK_STATUS_VALUES(_) _(Normal) _(ModifiedLocally) _(CreatedLocally)
    
      enum TaskStatus { TASK_STATUS_VALUES(TASK_STATUS_ENUM_COMA) };
    
      #define STRINGIFY_VALUE(v) "ts" #v
      #define ENUM_TO_STR(x) if (status == TASK_STATUS_ENUM(x)) return STRINGIFY_VALUE(x);
    
      char* enumToStr(TaskStatus status) {
        TASK_STATUS_VALUES(ENUM_TO_STR);
        return STRINGIFY_VALUE(Normal);
      }

------
sown
We have these in our main product at work. They are powerful and very useful
but they can get out of hand and be difficult to debug or add code to.

