News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

why is the result different in debug and release mode?

Started by facat, April 15, 2011, 08:12:35 PM

Previous topic - Next topic

facat

recently i was faced up with a strange problem. When I built my project in debug mode, the result was totally wrong. When in release mode, the the result was perfectly right.
I was confused why the result was different in debug mode and release mode ? Did i invoke any bug in gcc?
I was using Code Block 10.5.
My project is in the attachment. There are some western characters in my files. They are my notes, so just ignore them.

oBFusCATed

It is pretty normal, most of the time there is a bug in you program... use the debugger to find it...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

facat

Quote from: oBFusCATed on April 15, 2011, 08:47:37 PM
It is pretty normal, most of the time there is a bug in you program... use the debugger to find it...
i've searched for some information on the internet. according to other's experience, always the result from debug is right, that from release is not right. here, my debug result is wrong, the release result is right. so i think it's strange.




stahta01

Do NOT try to add MSVC Libraries to your MinGW Debug Build.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

facat

Quote from: stahta01 on April 16, 2011, 02:25:29 AM
Do NOT try to add MSVC Libraries to your MinGW Debug Build.


i didn't use MSVC lib. by the way, my program is normal either in debug or release within VS2005.



facat

in addition,i uesed STL in my program. is there any posibility that STL has something to do my my strang program. 

stahta01

#6
Quote from: facat on April 16, 2011, 02:33:28 AM
Quote from: stahta01 on April 16, 2011, 02:25:29 AM
Do NOT try to add MSVC Libraries to your MinGW Debug Build.


i didn't use MSVC lib. by the way, my program is normal either in debug or release within VS2005.




Then why did you do so in the zipped project file.

Edit: If you do not believe me; just turn on Full Compiler Logging and look at the g++ linker command and you will see the .lib file trying to be linked on debug build.
http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F

Tim S.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

huzhongshan

maybe you have to check intermediate result of your function and compare it with correct one to find what cause the difference.

facat

Quote from: stahta01 on April 16, 2011, 04:51:15 AM
Quote from: facat on April 16, 2011, 02:33:28 AM
Quote from: stahta01 on April 16, 2011, 02:25:29 AM
Do NOT try to add MSVC Libraries to your MinGW Debug Build.


i didn't use MSVC lib. by the way, my program is normal either in debug or release within VS2005.




Then why did you do so in the zipped project file.

Edit: If you do not believe me; just turn on Full Compiler Logging and look at the g++ linker command and you will see the .lib file trying to be linked on debug build.
http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F

Tim S.
i removed that lib from my project,but the result is still wrong. I tried to change my template argument from double to long double ,this time result is right.

facat

does debug and release have different float precision?

facat

the result if right even when i changed the template argument to float. but it executed more loops than the release one, which still means the debug one and release one is different.

facat

when i tick "Optimize more( for speed [-O1])" in debug project, the result is the same the a release one.

ollydbg

Quote from: facat on April 16, 2011, 07:51:43 AM
when i tick "Optimize more( for speed [-O1])" in debug project, the result is the same the a release one.
mostly(probably)
1, this is a compiler bug, which produce different target code and different behavior.
2, some lib conflict. e.g. you app use a debug version CRT, then your lib use some release version CRT, then this will cause some error.

The important is: all these kind of bug is not related to Codeblocks, Codeblocks is only an IDE, and we give a convenient programming environment.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

facat

Quote from: ollydbg on April 16, 2011, 10:03:05 AM
Quote from: facat on April 16, 2011, 07:51:43 AM
when i tick "Optimize more( for speed [-O1])" in debug project, the result is the same the a release one.
mostly(probably)
1, this is a compiler bug, which produce different target code and different behavior.
2, some lib conflict. e.g. you app use a debug version CRT, then your lib use some release version CRT, then this will cause some error.

The important is: all these kind of bug is not related to Codeblocks, Codeblocks is only an IDE, and we give a convenient programming environment.
i prone to regard it as a compile bug. can i update the gcc in my Code Block to a higher version, and how?

ollydbg

Quote from: facat on April 16, 2011, 10:40:50 AM
i prone to regard it as a compile bug. can i update the gcc in my Code Block to a higher version, and how?
yes, you can use another compiler, you just need to configure the path in: menu->settings->compiler and debugger settings->compiler's installation directory. :D
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.