-
July 4th, 2012, 05:04 PM
#1
VC++ numerical difference executable
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
-
July 4th, 2012, 06:19 PM
#2
Re: VC++ numerical difference executable
Originally Posted by ArashCKar
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?
Your program has a bug.
Let's see the code.
Regards,
Paul McKenzie
-
July 4th, 2012, 07:50 PM
#3
Re: VC++ numerical difference executable
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.
-
July 4th, 2012, 08:47 PM
#4
Re: VC++ numerical difference executable
Not much we can do without code. You probably didn't initialize something.
-
July 4th, 2012, 11:58 PM
#5
Re: VC++ numerical difference executable
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.
-
July 5th, 2012, 12:45 AM
#6
Re: VC++ numerical difference executable
Originally Posted by ArashCKar
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.
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.
It is a huge code. I cannot post it.
So what do you want us to do? We can't solve problems without seeing what you're doing.
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
Last edited by Paul McKenzie; July 5th, 2012 at 08:31 PM.
-
July 5th, 2012, 12:55 AM
#7
Re: VC++ numerical difference executable
Originally Posted by ArashCKar
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.
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;
}
Run this program. What do you expect to be printed out on the console?
This is a perfect, tiny example of a program that can exhibit different behaviour, all because of an uninitialized variable.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; July 5th, 2012 at 12:58 AM.
-
July 5th, 2012, 03:39 PM
#8
Re: VC++ numerical difference executable
If this code uses floating point (float, double), then results can be different in debug and release builds due to optimisations.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|