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
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
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?
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