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 thoughts on “Preprocessor Tricks”

  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;

Leave a Reply

Your email address will not be published.