C/C++中可以用 #undef xxx 来取消 宏xxx 的定义。
举例如下
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
// xxx is defined
bool b = true;
#define xxx
#ifdef xxx
cout << "xxx is defined #1" << endl; // this line is printed
#endif
// undefine xxx
#ifdef xxx
#undef xxx
b = true;
#endif
#ifdef xxx
cout << "xxx is defined #2" << endl; // not printed
#endif
// define xxx again
if (b)
{
#define xxx
}
#ifdef xxx
cout << "xxx is defined #3" << endl; // printed
#endif
return 0;
}
结果输出:
xxx is defined #1
xxx is defined #3