CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 1999
    Posts
    7

    Debug/Release problem in C++ code...

    #include <math.h>

    void CMyDlg::OnButton2()
    {
    // m_a = 12.0; // if this is a local variable, then is it ok...
    double c = 3.141 * m_a;
    double b = cos(c);

    CString s;
    s.Format("%f, %f", m_a, b);
    AfxMessageBox(s);
    }

    The problem is that the program behaves unlikely in debug and release mode,
    if the m_a is a local variable then it is ok
    Any idea?
    thanks



  2. #2
    Join Date
    May 1999
    Location
    Bern, Switzerland
    Posts
    12

    Re: Debug/Release problem in C++ code...

    Have you made sure that m_a is initialized (i.e. was assigned a value) in the constructor of CMyDlg?
    Regards. Karl


  3. #3
    Guest

    Re: Debug/Release problem in C++ code...

    Have you checked to make sure the declaration of m_a is not bracketed by any
    #ifdef _DEBUG statements?


  4. #4
    Guest

    Re: Debug/Release problem in C++ code...

    What type is m_a? If it is a class, make sure you explicitly convert it to a double in your Format() method. Format() is a variable args function so it knows nothing about the type. If m_a is a class, the compiler will push the whole m_a object onto the stack (pass by value). Try this:

    void CMyDlg::OnButton2()
    {
    // m_a = 12.0; // if this is a local variable, then is it ok...
    double c = 3.141 * m_a;
    double b = cos(c);
    double a = m_a; // implicit cast.
    CString s;
    s.Format("%f, %f", a, b);
    AfxMessageBox(s);
    }

    Chris Hafey


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured