Hi All,
Does anybody know why I get difference numerical results when I run the executable file directly and when I use the VS environment to run the program?
Thanks a lot,
Arash
Printable View
Hi All,
Does anybody know why I get difference numerical results when I run the executable file directly and when I use the VS environment to run the program?
Thanks a lot,
Arash
Thank you Paul,
It is a huge code. I cannot post it. It works fine when ran from the debugger both under debug and release mode but when running the executable under exactly identical circumstances produce a different result.
Not much we can do without code. You probably didn't initialize something.
Its just like asking a doctor that you are sick and give you a medicine, where you can't tell the doctor that what is wrong with you, neither you let him examine you ;)
There can be so many things that go wrong, such as un-initialization of something (as pointed out by GCDEF) or if you are using floats/doubles then due to floating point inaccuracy, you may get different numerical results, who knows...
Try to replicate the issue in a small test program and post it here.
You are not running the program "under exactly identical circumstances". One way, you're running under the debugger, and in another way, you're not running under a debugger. Those are two different circumstances. If your C++ program has certain types of bugs, then there is no guarantee how it will run or what results you will get. It could even run OK today and not run OK tomorrow.
As others pointed out,
1) You may have uninitialized variables -- this means that your program will exhibit undefined behaviour.
2) You may not be checking all return values from functions you're calling, causing your program to exhibit undesired behaviour.
3) You may be expecting to read values from a file, and the file doesn't exist or it's the wrong file (again, causing different behaviour).
4) You may be overrunning the boundaries of an array or trashing memory in some other way, meaning your program will exhibit undefined behaviour.
I can list many more things.
So what do you want us to do? We can't solve problems without seeing what you're doing.Quote:
It is a huge code. I cannot post it.
All I can say is that your program has a bug, and you need to debug it. Having a program behave differently when run under a debugger, on another computer, on a different day of the week, etc. is not uncommon, and it's all due to the items I listed above (and even more reasons I didn't list).
Regards,
Paul McKenzie
Run this program. What do you expect to be printed out on the console?Code:#include <iostream>
class foo
{
bool bValue;
public:
bool getValue() const { return bValue; }
};
int main()
{
foo f;
double dValue;
if ( f.getValue() )
dValue = 1.0;
else
dValue = 0.0;
std::cout << dValue;
}
This is a perfect, tiny example of a program that can exhibit different behaviour, all because of an uninitialized variable.
Regards,
Paul McKenzie
If this code uses floating point (float, double), then results can be different in debug and release builds due to optimisations.