I’m running into this issue. This is not about macro functions, just simple string-value macro replacement.
I have two header files
test1.h
#define TEST 123
test2.h
#define TEST 456
Now I have a program included both these two headers, but I want my actually TEST to be 123.
How can I avoid defining TEST as 456?
You might think I’m crazy not to simply change the macro, but the situation is: I have a third-party decoder, which has this macro (defined in test1.h), and there’s another WINAPI macro (defined in test2.h). Both of these files are controlled by others; I should not change either of them.
I don’t need the test2.h at all, but I guess it’s implicitly included by some other WINAPI header.
So, could anyone please tell me how to work around this issue? To overwrite the WINAPI macro with my third-party macro? Or how to nullify the definition from the WINAPI header in my own code? Is there a way to specify which header I don’t want to include.
You can use the
#ifdefpre-processor directive to determine ifTESTis defined already for your particular case. Or just#undefit first.Put that in your header file where you want
TESTto be 123 and not 456. Also, this needs to be beforetest1.h.