Author Topic: why is the result different in debug and release mode?  (Read 23037 times)

Offline facat

  • Multiple posting newcomer
  • *
  • Posts: 19
why is the result different in debug and release mode?
« on: April 15, 2011, 08:12:35 pm »
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: why is the result different in debug and release mode?
« Reply #1 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...
(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!]

Offline facat

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: why is the result different in debug and release mode?
« Reply #2 on: April 16, 2011, 02:12:53 am »
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.




Online stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: why is the result different in debug and release mode?
« Reply #3 on: April 16, 2011, 02:25:29 am »
Do NOT try to add MSVC Libraries to your MinGW Debug Build.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline facat

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: why is the result different in debug and release mode?
« Reply #4 on: April 16, 2011, 02:33:28 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.



Offline facat

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: why is the result different in debug and release mode?
« Reply #5 on: April 16, 2011, 03:43:21 am »
in addition,i uesed STL in my program. is there any posibility that STL has something to do my my strang program. 

Online stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: why is the result different in debug and release mode?
« Reply #6 on: April 16, 2011, 04:51:15 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.
« Last Edit: April 16, 2011, 04:55:06 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline huzhongshan

  • Multiple posting newcomer
  • *
  • Posts: 109
Re: why is the result different in debug and release mode?
« Reply #7 on: April 16, 2011, 04:52:58 am »
maybe you have to check intermediate result of your function and compare it with correct one to find what cause the difference.

Offline facat

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: why is the result different in debug and release mode?
« Reply #8 on: April 16, 2011, 07:12:03 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.
« Last Edit: April 16, 2011, 07:37:57 am by facat »

Offline facat

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: why is the result different in debug and release mode?
« Reply #9 on: April 16, 2011, 07:29:09 am »
does debug and release have different float precision?

Offline facat

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: why is the result different in debug and release mode?
« Reply #10 on: April 16, 2011, 07:39:00 am »
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.

Offline facat

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: why is the result different in debug and release mode?
« Reply #11 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.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: why is the result different in debug and release mode?
« Reply #12 on: April 16, 2011, 10:03:05 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.

Offline facat

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: why is the result different in debug and release mode?
« Reply #13 on: April 16, 2011, 10:40:50 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?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: why is the result different in debug and release mode?
« Reply #14 on: April 16, 2011, 10:43:37 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.