Possible Duplicate:
Can I redefine a c++ macro for a few includes and then define it back?
I have the following:
#include <iostream>
#define A 1 // define a macro
#define B A // copy macro? (note this does not work...)
#undef A // undefine first macro
#define A 2 // redefine it as something else
int main (int argc, const char * argv[])
{
std::cout << A << " " << B;
return 0;
}
My program prints "2 2". I want it to print "2 1". How do I do this? (BTW, please forgive the mixing of C++ in a C question. I really just care about the preprocessor portion of the question, which I would like to be C99 compliant.)
Eventually I would like to do something like:
// In file A
#define A 1 // define a macro
// In file B
#include "fileA.h"
#define B A // copy macro?
#undef A // undefine first macro
#define A 2 // redefine it as something else
// #include other files using A
#define A B // set macro back to original value, whatever that was.
UPDATE - Already answered here: