程序如下:
- #include <iostream>
- using namespace std;
-
- int main()
- {
- #ifdef _DEBUG // 注意:只有一个下划线
- cout << "debug" << endl;
- #else
- cout << "release" << endl;
- #endif
-
- return 0;
- }
结果为:debug
在VC6.0下,点击Build, Set Active Configuration,可以发现,上述结果对应的是debug, 现在我们切换成release选项,运行上面的程序,结果为:release
我们知道,assert非常常用,下面看看assert在debug和release中的不同行为,程序如下:
- #include <iostream>
- #include <cassert>
- using namespace std;
-
- int main()
- {
- cout << "haha" << endl;
- assert(0 == 1);
- cout << "hehe" << endl;
-
- return 0;
- }
在debug版本中会出错,因为0和1不相等,结果为:
在release版本中的结果为:
haha
hehe
由此可见,在release中,assert根本没有用,直接被忽视。