From Electron Cloud
Jump to: navigation, search
(New page: ==Stringify a define== If you would like to pass a string into a define via the compiler -D directive, but need to use it as if it was a quoted #define, it takes a pair of macros (verified...)
(No difference)

Revision as of 16:27, 28 April 2009

Stringify a define

If you would like to pass a string into a define via the compiler -D directive, but need to use it as if it was a quoted #define, it takes a pair of macros (verified to work on g++ and also Visual Studio):

#define STRINGIFY_IMPL(S) #S
#define STRINGIFY(s) STRINGIFY_IMPL(s)

then it can be used like this:

QFile uiFile(":" STRINGIFY(UI_FILE));

and in the .pro file if using Qt:

DEFINES += UI_FILE="some.ui"

so when it's compiled:

g++ foo.cpp -DUI_FILE=some.ui ...

(oh noes, it's DUI!)