Click to See Complete Forum and Search --> : Debug/Release problem in C++ code...


Petr Stejskal
April 2nd, 1999, 06:13 AM
#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

Karl Spaelti
April 2nd, 1999, 06:34 AM
Have you made sure that m_a is initialized (i.e. was assigned a value) in the constructor of CMyDlg?
Regards. Karl

April 6th, 1999, 10:33 AM
Have you checked to make sure the declaration of m_a is not bracketed by any
#ifdef _DEBUG statements?

April 6th, 1999, 01:58 PM
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