473,413 Members | 1,731 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Strange Problem

Hi,

I'm sorry about the vagueness of this post but I don't really know how
to present the problem.

I am writing a numerical integrator and currently the program gets
stuck and I am forced to abort it. When I attempt to add debug code
such as cout << ..., The problem goes away. I can't even pinpoint the
section of code which is causing the problem (this is why I haven't
included any code). I can't understand how the addition of a cout
command could affect the program in this way and I'm going crazy. Does
anyone have any advice?

Thanks

Jul 23 '05 #1
4 1061
tw*******@yahoo.com wrote:
I am writing a numerical integrator and currently the program gets
stuck and I am forced to abort it. When I attempt to add debug code
such as cout << ..., The problem goes away.


Probably adding the debugging has caused things to move around in
memory. Something is going wrong and corrupting a bit of memory;
without the debugging, it hits something that matters. With the
debugging, by chance it hits something that doesn't matter.

So... Use a debugger. Unlike putting explicit debugging in the code,
running under a debugger should preserve the same memory layout.

Or, since the problem is likely to be something memory-related, try a
memory access tracing tool like Purify or Valgrind.

--Phil.
Jul 23 '05 #2
tw*******@yahoo.com wrote:
I'm sorry about the vagueness of this post but I don't really know how
to present the problem.

I am writing a numerical integrator and currently the program gets
stuck and I am forced to abort it. When I attempt to add debug code
such as cout << ..., The problem goes away. I can't even pinpoint the
section of code which is causing the problem (this is why I haven't
included any code). I can't understand how the addition of a cout
command could affect the program in this way and I'm going crazy. Does
anyone have any advice?


I've seen it happen and it _can_ be a compiler bug related to the way
the code is generated. It is rather rare. I've had a case where some
variable wouldn't get updated with the result of evaluating of some
expression unless there was a 'cout' thing inserted in the vicinity
of the assignment operator. Awful. I could only find it by making
a release build with debug information (optimisations turned on and
the debug symbols created in a separate file) and actually looking at
the assembly code while stepping through the program. I don't wish
anybody would have to do the same, although sometimes one has to reach
far to get it. I eventually fixed it by declaring that variable as
'volatile'.

What advice to give? Try adding debugging info and run it under the
debugger. Force the debugger to stop (interrupt) your application when
it reached the sticking point. See where it gets stuck. Try to narrow
it down to one function or a block of code. Proceed from that point.

V
Jul 23 '05 #3
Thanks a lot.

The problem turned out to be a function that returned a value that was
too small and was converted to NaN. I still have no idea why this
would be affected by cout statements.

Tommer

Jul 23 '05 #4
tw*******@yahoo.com wrote:
Thanks a lot.

The problem turned out to be a function that returned a value that was
too small and was converted to NaN.
Floating-point values that are too close to zero to represent are either
turned into subnormal values or coverted to zero. They don't become
NaN's. You get NaN's for things like 0.0/0.0, which has no meaningful value.
I still have no idea why this
would be affected by cout statements.


Probably because you're looking at corrupted memory, caused by writing
though a bad pointer. That's consistent with all the symptoms you
described initially, and corrupted floating-point values often look like
NaNs.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Rob Ristroph | last post by:
Hi, It's pretty unhelpful to post "I have a huge piece of code that crashes in strange places, what's the problem?" but that's basically my problem and I really am at my wit's end. The piece...
2
by: Paul Drummond | last post by:
Hi all, I am developing software for Linux Redhat9 and I have noticed some very strange behaviour when throwing exceptions within a shared library. All our exceptions are derived from...
25
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's...
2
by: TB | last post by:
I am seeing a very strange problem as follows... I have a loop where a fair amount of processing is going on and near the top of the loop I access a class that has only static helper functions...
1
by: Sam Kong | last post by:
Hello! Recently I had a strange problem with Visual C# 2005 beta 1. When I ran(F5 key) a program, <#if DEBUG> statement was not working. It ran as RELEASE mode. So I had to manually define...
8
by: Spam Trap | last post by:
I am getting strange resizing problems when using an inherited form. Controls are moving themselves seemingly randomly, but reproducibly. "frmBase" is my base class (a windows form), and...
11
by: Martin Joergensen | last post by:
Hi, I've encountered a really, *really*, REALLY strange error :-) I have a for-loop and after 8 runs I get strange results...... I mean: A really strange result.... I'm calculating...
12
by: StephQ | last post by:
I have a class Bounds with two constructors: class Bounds { private: list<SegmentupperLinearSpline; // Upper bound. list<SegmentlowerLinearSpline; // Lower bound. ....
8
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples....
5
by: ioni | last post by:
Good day, fellows! I have a strange problem – at my site there is a flash strip, that loads data dynamically. It works fine (grabs data from the remote server and presents it), however in IE7...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.