+ Reply to Thread
Results 1 to 2 of 2

Thread: Why this program behaves differently in Debug and Release mode?

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    24

    Why this program behaves differently in Debug and Release mode?

    I have following code:

    Code:
    class CMyClass
    {
    private:
    	int m_nValue ;
    public:
    	CMyClass(int nValue)
    	{
    		m_nValue = nValue ;
    
    		printf("CMyClass::CMyClass\n") ;
    	}
    
    	CMyClass(const CMyClass& obj)
    	{
    		m_nValue = obj.m_nValue ;
    
    		printf("CMyClass::CMyClass copy\n") ;
    	}
    
    	~CMyClass()
    	{
    		printf("CMyClass::~CMyClass\n") ;
    	}
    } ;
    
    CMyClass ReturnByValue(int nValue)
    {
    	CMyClass obj(nValue) ;
    
    	return obj;
    } ;
    
    void UseReturnByValue()
    {
    	ReturnByValue(10) ;
    }
    Output:
    a. Debug mode:
    CMyClass::CMyClass
    CMyClass::CMyClass copy
    CMyClass::~CMyClass
    CMyClass::~CMyClass

    b. Release mode
    CMyClass::CMyClass
    CMyClass::~CMyClass

    Why is this difference? What is the reason behind this?

    I am using Visual Studio 2005.

    Please help.

  2. #2
    Junior Member
    Join Date
    Feb 2012
    Posts
    49
    In VS 2005, Debug and Release mode application will compiled using different compiler and optimization options.

    This is the cause of this issue.

    In Release mode you application will run fast as it is optimized to run fast.

    While in Debug mode, you should be able to debug the application properly and is not optimized.

    See -> Project Properties -> Configuration Properties -> C/C++ -> Optimization ->

    You see that for Debug and Release modes this property is defined differently!

    hope this helps.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts