I want to replace a macro with a proper typedef with the same name. I have
#define FooType char*
in a third party library and this breaks some of my code (more precisely: some code I am forced to use and which I can't change by myself). I want to replace it by a typedef of the same name and then #undef
the macro. I tried something like that:
#define TMP_MACRO FooType
#undef FooType
typedef TMP_MACRO FooType;
#undef TMP_MACRO
But the preprocessor expands this to:
typedef FooType FooType;
(at least that is what g++ -E
told me). So the macro TMP_MACRO
is not expanded immediatelly. As 'FooType' is not there, it does not compile.
How can I replace the macro FooType
by a proper type and undefine the macro afterwards? Or is this impossible?
A typedef
declaration is usually on one line, but line numbers mean nothing to the compiler.
typedef FooType
#undef FooType
FooType;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With