• assert()在Release模式是不会起作用的


    唉,不能道听途说,"assert()在Release模式也会起作用的",需要自己动手测试才行。

    下面的测试证明:assert函数在Release模式是不会起作用的。

    测试类CTestClass:

    #pragma once
    
    #include <iostream>
    #include <assert.h>
    using namespace std;
    
    class CTestClass
    {
    public:
        CTestClass(UINT iPosBegin, UINT iPosEnd)
        {
            m_iPosBegin = iPosBegin;
            m_iPosEnd = iPosEnd;
            m_iExpectSize = m_iPosEnd - m_iPosBegin;
            assert(m_iExpectSize > 0);
        }
        ~CTestClass(){}
    
        void OutputInfo()
        {
            cout<<"------------------Output Info Begin---------------------"<<endl;
            cout<<"Position Begin:	"<<m_iPosBegin<<endl;
            cout<<"Position End:	"<<m_iPosEnd<<endl;
            cout<<"Segment Length:	"<<m_iExpectSize<<endl;
            cout<<"------------------Output Info  End---------------------"<<endl;
        }
    
        INT64 m_iPosBegin;
        INT64 m_iPosEnd;
        INT64 m_iExpectSize;//Mustn't use UINT64 coz it may be negative
    };

    调用方法:

    void main()
    {
        #define  SAFE_DELETE_OBJECT(obj) if(obj) {delete obj; obj = NULL;}
    
        CTestClass* obj1 = new CTestClass(10, 100);
        if(obj1)
            obj1->OutputInfo();
        else
            cout<<"Object 1 Create Failed."<<endl;
    
        CTestClass *obj2 = new CTestClass(100, 10);
        if(obj2)
            obj2->OutputInfo();
        else
            cout<<"Object 2 Create Failed."<<endl;
        
        SAFE_DELETE_OBJECT(obj1);
        SAFE_DELETE_OBJECT(obj2);
    
        system("pause");
    }

    Release模式下测试结果:

    ------------------Output Info Begin---------------------
    Position Begin: 10
    Position End:   100
    Segment Length: 90
    ------------------Output Info  End---------------------
    ------------------Output Info Begin---------------------
    Position Begin: 100
    Position End:   10
    Segment Length: -90
    ------------------Output Info  End---------------------
    请按任意键继续. . .

  • 相关阅读:
    从B树、B+树、B*树谈到R 树
    从LSM-Tree、COLA-Tree谈到StackOverflow、OSQA
    Linux Kafka源码环境搭建
    CentOS 关闭图形用户界面
    部署与管理ZooKeeper(转)
    spark 2.0.0集群安装与hive on spark配置
    hive on spark的坑
    Spark2.0.0源码编译
    hive spark版本对应关系
    CentOS7 设置集群时间同步
  • 原文地址:https://www.cnblogs.com/tupx/p/3485128.html
Copyright © 2020-2023  润新知