Is there a solution?
There is a whole world of ways you can combine macro expansion with conditional compilation. It's unclear which of them you would consider a solution, but here's a possibility:
#define doubledouble 1
#define floatfloat 1
#define concat_literal(x,y) x ## y
#define realtype(t1,t2) concat_literal(t1,t2)
// ...
#define REAL float
#if realtype(REAL, double)
// REAL is double
#elif realtype(REAL, float)
// REAL is float
#else
// REAL is something else
#endif
The realtype
macro works by macro-expanding its arguments and concatenating them together. On rescan, if the result is doubledouble
or floatfloat
then that is expanded further to 1. If it is an identifier that is not defined as a macro name, then the #if
treats it as 0.
It's not foolproof, of course. It does not work if REAL
has a multi-token expansion, such as long double
. There's also a minor risk of collision with other defined macro names.