473,880 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

debugging -- behaviour to be explained.

I am debugging a program to price options which involves a recursive
function:

double node::get_equit y(Parameter * const params_ptr, int x, int y,
const int rights)

This recursive function is behaving oddly. I made it print statements
into a debug file to try and capture the anomalous behaviour, and I did
capture something that to me (as a newbie) is very puzzling.
The function includes this block of code:

debug << endl << "This puzzles me!!";
debug << endl << "rights" << rights;
debug << endl << "That's the puzzle";

That block of 3 lines occurs consecutively. It is a brief excerpt,
yes, but nothing is left out of the middle.

The first two lines give me exactly the output I expected.

However, the third line gives me nothing. In other words, "That's the
puzzle" appears nowhere.

How can this be?

I am a beginner so don't be afraid to make suggestions that would mean
I did something stupid.

However, I was obviously printing to the debug stream successfully
because I was successful in getting the first line "This puzzles..." to
print as expected. (The 2nd line printed fine, too.)

What seems to be happening is that some of my code is simply being
ignored and I don't know why.

That block of 3 lines is part of a loop which is executed several
times. Each time, the 3rd line "That's the puzzle" is mysteriously
missing.

(I am having great trouble using the dev c++ debugger so I'm making do
without it. And yes, I did use the dev c++ help manual for the
debugger.)

Thank you for your help.

Paul Epstein

Jan 14 '06 #1
12 1641

<pa**********@a tt.net> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
I am debugging a program to price options which involves a recursive
function:

double node::get_equit y(Parameter * const params_ptr, int x, int y,
const int rights)

This recursive function is behaving oddly. I made it print statements
into a debug file to try and capture the anomalous behaviour, and I did
capture something that to me (as a newbie) is very puzzling.
The function includes this block of code:

debug << endl << "This puzzles me!!";
debug << endl << "rights" << rights;
What does the identifier 'rights' denote?
debug << endl << "That's the puzzle";

That block of 3 lines occurs consecutively. It is a brief excerpt,
yes, but nothing is left out of the middle.
But you did leave out important parts. Put together
a small, *compilable* example that produces the problem
behavior and post it here.

The first two lines give me exactly the output I expected.

However, the third line gives me nothing. In other words, "That's the
puzzle" appears nowhere.

How can this be?


With the very limited information you give, I can only hazard
a guess that something about whatever the name 'rights' represents
is doing something unexpected to your stream.

-Mike
Jan 14 '06 #2
pauldepst...@at t.net schrieb:
I am debugging a program to price options which involves a recursive
function:

double node::get_equit y(Parameter * const params_ptr, int x, int y,
const int rights)

This recursive function is behaving oddly. I made it print statements
into a debug file to try and capture the anomalous behaviour, and I did
capture something that to me (as a newbie) is very puzzling.
The function includes this block of code:

debug << endl << "This puzzles me!!";
debug << endl << "rights" << rights;
debug << endl << "That's the puzzle";

That block of 3 lines occurs consecutively. It is a brief excerpt,
yes, but nothing is left out of the middle.

The first two lines give me exactly the output I expected.

However, the third line gives me nothing. In other words, "That's the
puzzle" appears nowhere.

How can this be?

I am a beginner so don't be afraid to make suggestions that would mean
I did something stupid.

However, I was obviously printing to the debug stream successfully
because I was successful in getting the first line "This puzzles..." to
print as expected. (The 2nd line printed fine, too.)

What seems to be happening is that some of my code is simply being
ignored and I don't know why.

That block of 3 lines is part of a loop which is executed several
times. Each time, the 3rd line "That's the puzzle" is mysteriously
missing.

(I am having great trouble using the dev c++ debugger so I'm making do
without it. And yes, I did use the dev c++ help manual for the
debugger.)

Thank you for your help.

Paul Epstein


Write to std::cerr instead to debug because it this stream is
never buffered.
Also I don't understand why you first write std::endl and then
the content, but that's a matter of style.

Regards, Stephan
br****@osb-systems.com
Open source rating and billing engine for communication networks.

Jan 14 '06 #3

Thanks, Mike.

rights is an integer variable.

My intent is to create a recursive function where rights is a
parameter, and where the definition is recursive in terms of rights-1
etc.

One step is to ask it what value it thinks the parameter takes -- it
answered how I thought -- 2.

I will try and make a compilable example out of this. But it's tricky
to disentangle it that way -- I know that probably means I have bad
coding style.

I don't see how rights would do anything to the stream.

Conceptually what I'm trying to do is define f(rights) by saying if
(rights==0) return ...;

if (rights > 0) return f(rights - 1,...);

I will think about how I can disentangle the bits and pieces to provide
a complete example.

Paul Epstein

Jan 14 '06 #4
Thanks.

I'm not familiar with cerr but I'm happy to google it. Is the command
just cerr<< .. (combined with using namespace std;) ?

I use std::endl to print on a new line. Are you advocating \n instead?

Paul Epstein

Jan 14 '06 #5
TB
pa**********@at t.net sade:
I am debugging a program to price options which involves a recursive
function:

double node::get_equit y(Parameter * const params_ptr, int x, int y,
const int rights)

This recursive function is behaving oddly. I made it print statements
into a debug file to try and capture the anomalous behaviour, and I did
capture something that to me (as a newbie) is very puzzling.
The function includes this block of code:

debug << endl << "This puzzles me!!";
debug << endl << "rights" << rights;
debug << endl << "That's the puzzle";

<snip>

And 'debug' is what? In what context is it used?

TB
Jan 14 '06 #6

TB wrote:
pa**********@at t.net sade:
I am debugging a program to price options which involves a recursive
function:

double node::get_equit y(Parameter * const params_ptr, int x, int y,
const int rights)

This recursive function is behaving oddly. I made it print statements
into a debug file to try and capture the anomalous behaviour, and I did
capture something that to me (as a newbie) is very puzzling.
The function includes this block of code:

debug << endl << "This puzzles me!!";
debug << endl << "rights" << rights;
debug << endl << "That's the puzzle";
<snip>

And 'debug' is what? In what context is it used?

TB


debug is a stream for a text file. I use it to print variables for
debugging.

I followed Stephen's advice just now using cerr, and there were no
anomalies.

Perhaps the fact that debug << endl << "That's the puzzle" failed could
be used to find a significant problem with the recursion.

I am still very puzzled by that. I can think of no earthly reason why
I wouldn't get "That's the puzzle" printed in the line after the word
"rights" occurs. This happens when I use the cerr stream but not when
I use debug.

Maybe, if I understood this, I would see the whole problem and resolve
it quickly.

Paul Epstein.

Jan 14 '06 #7
pa**********@at t.net schrieb:

I'm not familiar with cerr but I'm happy to google it. Is the command
just cerr<< .. (combined with using namespace std;) ? std::cerr is the (unbuffered) standard error output while
std::cout is the (buffered) standard output.
I've suggested to use std::cerr because I don't know the behavior of
debug:-?

Also, if you debug make sure the output is flushed,
either with std::endl or std::flush as last argument.

I use std::endl to print on a new line. Are you advocating \n instead?

Yes, except for the <b>terminatin g</b> newline:
std::cout << "Hello " << name << ",\n"
<< "welcome back" << std::endl;

Regards, Stephan
br****@osb-systems.com
Open source rating and billing engine for communication networks.

Jan 14 '06 #8
pa**********@at t.net schrieb:
I followed Stephen's advice just now using cerr, and there were no
anomalies.

Perhaps the fact that debug << endl << "That's the puzzle" failed could
be used to find a significant problem with the recursion.

Just come to my mind: and if you use std::cout instead of debug?

Stephan

Jan 14 '06 #9

<pa**********@a tt.net> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .

TB wrote:
pa**********@at t.net sade:
I am debugging a program to price options which involves a recursive
function:

double node::get_equit y(Parameter * const params_ptr, int x, int y,
const int rights)

This recursive function is behaving oddly. I made it print statements
into a debug file to try and capture the anomalous behaviour, and I did capture something that to me (as a newbie) is very puzzling.
The function includes this block of code:

debug << endl << "This puzzles me!!";
debug << endl << "rights" << rights;
debug << endl << "That's the puzzle";

<snip>

And 'debug' is what? In what context is it used?

TB


debug is a stream for a text file. I use it to print variables for
debugging.

I followed Stephen's advice just now using cerr, and there were no
anomalies.

Perhaps the fact that debug << endl << "That's the puzzle" failed could
be used to find a significant problem with the recursion.

I am still very puzzled by that. I can think of no earthly reason why
I wouldn't get "That's the puzzle" printed in the line after the word
"rights" occurs. This happens when I use the cerr stream but not when
I use debug.

Maybe, if I understood this, I would see the whole problem and resolve
it quickly.

Paul Epstein.

The reason you are missing the third line is that you have not added an endl
after
it, the data may not be necessarily flushed without the endl. I'd suggest
bracketing
the text you want to output with endl's or adding a flush after each output
to ensure
the text is captured in your debug output. Try that and see if your output
makes more
sense.

debug << endl << "This puzzles me!!";
debug << endl << "rights" << rights;
debug << endl << "That's the puzzle";

Jan 15 '06 #10

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

Similar topics

0
1487
by: Gary | last post by:
I have problem in debugging a solution. The steps are explained below. 1. Build the solution which has some 100 projects. 2. goto debug mode, the IDE starts verifying the build for all the projects even though they are not build and simply skips. 3. This is taking some time before real debugging starts. So is there a way
25
4345
by: Jeff | last post by:
Use the MS Script Editor included free with MS Office 2002 and above, for debugging Internet Explorer (IE). This subject is of great interest to many JS developers, as there is no obvious, low cost way to do sophisticated debugging in IE6 other than to use the debugger described below, which is horribly documented otherwise. I feel debugging is an important aspect of projecting the useability of the language and needs to be made more...
6
25206
by: Dmitri Shvetsov | last post by:
Hi All, Did somebody see the situation when the VS refuses to debug the Web Service at all? I can't catch why, the initially created Web Service can be debugged very easy but after some changes in a source code, maybe the source code becomes bigger that some hidden threshold, the debugger can't enter into this code anymore. I can use this web service, all methods but can't see in debugger what's going on. I have already catched this...
3
3651
by: R Millman | last post by:
under ASP.NET, single stepping in debug mode appears not to stop within event procedures. i.e. 1) Create web page with submit button and event procedure for the click event in the code behind page, 2) Breakpoint in the Page_Load, 3) debug the web page and click the submit button, 4) "step into" under debug several times, 5) The debugger does not stop at any of the statements in the click event handler. A breakpoint is needed in each...
16
4232
by: Serdar Kalaycý | last post by:
Hi everybody, My problem seems a bit clichè but I could not work around. Well I read lots of MSDN papers and discussions, but my problem is a bit different from them. When I tried to run the project in debug mode (by hitting F5) it gives an error message "Error while trying to run project: Unable to start debugging on the web server.
1
2267
by: Teemu Keiski | last post by:
Hi, I have following type of scenario (also explained here http://blogs.aspadvice.com/joteke/archive/2005/01/10/2196.aspx ) We have problematic web server (wink2 Standard, 1.5GB of physical memory, SQL 2000 in same box, framework 1.0 and 1.1 installed, apps use mainly 1.0) whose aspnet_wp.exe's memory consumption increases slowly but surely, leading to process restart eventually and then again recollecting memory etc etc
6
1448
by: ?scar Martins | last post by:
Hi When I'm debugging and somewhere in the code I have a breakpoint, many times when the code after breakpoint finishes and the app returns I can do nothing within in it(it's like freeze)... The app behaves strangely and not accepts any event even close event!!!!! It just lefts for me to stop debugging clicking the respective button in the vs.net toolbar... I don't know if this behaviour is a bug of vs.net or if it's consequence of bad...
11
1409
by: Pranav | last post by:
The Code is compiling without Error/Bug/Exception.., What are the possibilities for this behaviour? //*************************************************************** #include<stdio.h> typedef struct abc_ *abc; static abc param; abc fun(void)
2
1026
by: Jan =?UTF-8?B?U2Now6RmZXI=?= | last post by:
Hi all, can anyone explain the behaviour of the following code sniplet: ---schnipp <--- class Base(object): def __init__( self, lst= ): self.varlist = lst def addVar( self, var ):
0
11093
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10715
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10811
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10396
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9550
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7951
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7105
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5973
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4596
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.