Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #64

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

Path csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!news.snarked.org!newsfeed.news.ucla.edu!usenet.stanford.edu!news.iecc.com!nerds-end
From torbenm@diku.dk (Torben Ægidius Mogensen)
Newsgroups comp.compilers
Subject Re: GCC/G++ compiler: Error goes away when run through debugger
Date Mon, 28 Mar 2011 11:25:32 +0200
Organization SunSITE.dk - Supporting Open source
Lines 29
Sender news@iecc.com
Approved comp.compilers@iecc.com
Message-ID <11-03-059@comp.compilers> (permalink)
References <11-03-054@comp.compilers>
NNTP-Posting-Host news.iecc.com
X-Trace gal.iecc.com 1301413973 18714 64.57.183.58 (29 Mar 2011 15:52:53 GMT)
X-Complaints-To abuse@iecc.com
NNTP-Posting-Date Tue, 29 Mar 2011 15:52:53 +0000 (UTC)
Keywords C++, debug
Posted-Date 29 Mar 2011 11:52:53 EDT
X-submission-address compilers@iecc.com
X-moderator-address compilers-request@iecc.com
X-FAQ-and-archives http://compilers.iecc.com
Xref x330-a1.tempe.blueboxinc.net comp.compilers:64

Show key headers only | View raw


"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

Back to comp.compilers | Previous | Next | Find similar


Thread

Re: GCC/G++ compiler: Error goes away when run through debugger torbenm@diku.dk (Torben Ægidius Mogensen) - 2011-03-28 11:25 +0200

csiph-web