2010-01-07

Preprocessor Tricks

This allows you to convert any preprocessor macro value to a string, e.g. for printing.

#include <iostream>

#define MEINMAKRO 1.3.4

#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)

int main()
{
std::cout << TOSTRING(MEINMAKRO) << std::endl;
return 0;
}

2 comments:

  1. you may also be interested in ##, from the TowerMadness source:

    #define ADD_PROFILE( name ) \
    static pProfiler profiler_##name;
    ADD_PROFILE(render,game);

    translates to

    static pProfiler profiler_render;

    ReplyDelete
  2. Cool, thanks for the hint.

    ReplyDelete