关键词搜索

源码搜索 ×
×

用程序判断设置的是debug还是release以及assert在debug和release版本中的不同行为

发布2013-05-13浏览8417次

详情内容

        程序如下:

 

  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. #ifdef _DEBUG // 注意:只有一个下划线
  6. cout << "debug" << endl;
  7. #else
  8. cout << "release" << endl;
  9. #endif
  10. return 0;
  11. }

      结果为:debug

 

     在VC6.0下,点击Build, Set Active Configuration,可以发现,上述结果对应的是debug, 现在我们切换成release选项,运行上面的程序,结果为:release
     

     我们知道,assert非常常用,下面看看assert在debug和release中的不同行为,程序如下:

 

  1. #include <iostream>
  2. #include <cassert>
  3. using namespace std;
  4. int main()
  5. {
  6. cout << "haha" << endl;
  7. assert(0 == 1);
  8. cout << "hehe" << endl;
  9. return 0;
  10. }

     在debug版本中会出错,因为0和1不相等,结果为:

 


 

       在release版本中的结果为:

haha
hehe
       由此可见,在release中,assert根本没有用,直接被忽视。

 

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载