Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: facat on April 15, 2011, 08:12:35 pm

Title: why is the result different in debug and release mode?
Post by: facat 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.
Title: Re: why is the result different in debug and release mode?
Post by: 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...
Title: Re: why is the result different in debug and release mode?
Post by: facat 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.



Title: Re: why is the result different in debug and release mode?
Post by: stahta01 on April 16, 2011, 02:25:29 am
Do NOT try to add MSVC Libraries to your MinGW Debug Build.
Title: Re: why is the result different in debug and release mode?
Post by: facat 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.


Title: Re: why is the result different in debug and release mode?
Post by: facat 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. 
Title: Re: why is the result different in debug and release mode?
Post by: stahta01 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.
Title: Re: why is the result different in debug and release mode?
Post by: huzhongshan 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.
Title: Re: why is the result different in debug and release mode?
Post by: facat 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.
Title: Re: why is the result different in debug and release mode?
Post by: facat on April 16, 2011, 07:29:09 am
does debug and release have different float precision?
Title: Re: why is the result different in debug and release mode?
Post by: facat 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.
Title: Re: why is the result different in debug and release mode?
Post by: 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.
Title: Re: why is the result different in debug and release mode?
Post by: ollydbg 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.
Title: Re: why is the result different in debug and release mode?
Post by: facat 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?
Title: Re: why is the result different in debug and release mode?
Post by: ollydbg 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
Title: Re: why is the result different in debug and release mode?
Post by: facat on April 16, 2011, 01:17:04 pm
how to update the gcc and g++ version in my CB?
Title: Re: why is the result different in debug and release mode?
Post by: facat on April 16, 2011, 07:01:35 pm
I compiled my project in my friend's computer. He has a AMD cpu. to my surprise, the result is right.
i'm using cpu I5, i think this has something to do with my cpu. maybe there is a complile bug on a I5 cpu computer?
Title: Re: why is the result different in debug and release mode?
Post by: oBFusCATed on April 16, 2011, 07:14:59 pm
The only way to be sure it is a compiler bug, is to check the assembly.
But I'm pretty sure you have a bug in you code, you just have to find it :)
Title: Re: why is the result different in debug and release mode?
Post by: facat on April 17, 2011, 06:59:49 am
The only way to be sure it is a compiler bug, is to check the assembly.
But I'm pretty sure you have a bug in you code, you just have to find it :)


code bug?then how can this explain that my project is normal in my vs2005 and in CB on my friend's AMD computer?
Title: Re: why is the result different in debug and release mode?
Post by: oBFusCATed on April 17, 2011, 08:56:23 am
Sometimes a bug is revealed by a special combination of computer, gcc, moon phaze, etc.
Also is you computer stable?

btw, this is not C::B related, so please ask more questions on the mingw/gcc mailing list
Title: Re: why is the result different in debug and release mode?
Post by: Jenna on April 17, 2011, 10:47:00 am
Due to optimization you might have different memory boundaries in debug and release code also some functions might be inlined with, but not without optimization.
And there are many other possible other sources of trouble.

This might be the cause for your errors.

You have to be sure that your code works stable on any system, with any byte-order and on 32 and 64-bit.

You can try to add some debug-statements (cout's or printf's) to find the place where something goes wrong.