Re: GCC/G++ compiler: Error goes away when run through debugger

torbenm@diku.dk (Torben Ęgidius Mogensen)
Mon, 28 Mar 2011 11:25:32 +0200

          From comp.compilers

Related articles
GCC/G++ compiler: Error goes away when run through debugger rhoads@cs.rutgers.edu (rhoads@cs.rutgers.edu) (2011-03-26)
Re: GCC/G++ compiler: Error goes away when run through debugger nospam@no.spam (Mark in Sutherland) (2011-03-27)
Re: GCC/G++ compiler: Error goes away when run through debugger bobduff@shell01.TheWorld.com (Robert A Duff) (2011-03-27)
Re: GCC/G++ compiler: Error goes away when run through debugger robin51@dodo.com.au (robin) (2011-03-28)
Re: GCC/G++ compiler: Error goes away when run through debugger Pidgeot18@verizon.invalid (Joshua Cranmer) (2011-03-27)
Re: GCC/G++ compiler: Error goes away when run through debugger torbenm@diku.dk (2011-03-28)
Re: GCC/G++ compiler: Error goes away when run through debugger bc@freeuk.com (BartC) (2011-03-28)
Re: GCC/G++ compiler: Error goes away when run through debugger gneuner2@comcast.net (George Neuner) (2011-03-29)
Re: GCC/G++ compiler: Error goes away when run through debugger gah@ugcs.caltech.edu (glen herrmannsfeldt) (2011-03-29)
Re: GCC/G++ compiler: Error goes away when run through debugger ike@localhost.claranet.nl (2011-03-29)
Re: GCC/G++ compiler: Error goes away when run through debugger gneuner2@comcast.net (George Neuner) (2011-03-31)
Re: GCC/G++ compiler: Error goes away when run through debugger shankarke@gmail.com (Shankar) (2011-04-01)
| List of all articles for this month |

From: torbenm@diku.dk (Torben Ęgidius Mogensen)
Newsgroups: comp.compilers
Date: Mon, 28 Mar 2011 11:25:32 +0200
Organization: SunSITE.dk - Supporting Open source
References: 11-03-054
Keywords: C++, debug
Posted-Date: 29 Mar 2011 11:52:53 EDT

"rhoads@cs.rutgers.edu" <rhoads@cs.rutgers.edu> writes:


> I have an C++ application program that is producing incorrect results
> but the error goes away when I run it through the debugger.
>
> When I used the -ggdb compiler flag so I can run it under the gdb
> debugger, the error goes away. It also runs fine if I do both of the
> following; extract a few of the input instances which generate
> incorrect results and put them in a separate input file.
> Use this input file and recompile the program with no optimization
> flags (I am otherwise using the -O3 optimization flag).


I have had a similar experience: My program was giving strange
results, so I inserted some print statements to write out intermediate
results. And promptly the problem disappeared. I traced the problem
to the compiler re-arranging some FP computations which caused a
change in the last bit, which made some values be unequal that would
otherwise be equal.


The moral is, of course, that I should not have used equality tests
for FP numbers, but instead used an "within epsilon" test. In
general, you should not expect FP calculations to give exactly the
same result after optimisation in C or C++, as the order of evaluation
is not fully specified and because the compiler might optimise a
multiplication followed by an addition to a multiply-and-add, which
can change rounding behaviour.


Torben



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.