I want to change the priority of the preprocessor define process.
see the following code:
#include <iostream> #include <sstream> #define $(x) << x << #define f(x) (#x) int main() { auto world = "universe!"; std::stringstream ss; ss << f(Hello $(world)) << std::endl; std::cout << ss.str(); return 0; } The code run, but the 'f' macro will always processed before the '$' macro.
The current output:
Hello $(world) Expected output:
Hello universe! Thx.
'f' macro will always processed before the '$' macro.I do not understand, if that wouldn't be the case, the output would be"Hello << world <<".fis(#x)means everything is going to be#x, there is no place where<<would be removed. The expansion would bef(Hello $(world))->f(Hello << world <<)->"Hello << world <<".