I am debugging a program to price options which involves a recursive
function:
double node::get_equity(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 12 1564
<pa**********@att.net> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com... I am debugging a program to price options which involves a recursive function:
double node::get_equity(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
pauldepst...@att.net schrieb: I am debugging a program to price options which involves a recursive function:
double node::get_equity(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.
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
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 pa**********@att.net sade: I am debugging a program to price options which involves a recursive function:
double node::get_equity(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
TB wrote: pa**********@att.net sade: I am debugging a program to price options which involves a recursive function:
double node::get_equity(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. pa**********@att.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>terminating</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. pa**********@att.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
<pa**********@att.net> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com... TB wrote: pa**********@att.net sade: I am debugging a program to price options which involves a recursive function:
double node::get_equity(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";
With cout, it works as expected.
Which is a pity. I want it to fail so that I can pinpoint the strange
behaviour.
Yes, it seemed to be about not flushing the buffer.
It works with debug << endl <<.... << endl;
A pity because I was hoping the problem would lead to an understanding
of why the algorithm was failing.
Thanks, anyway.
Incremental progress but still progress.
Paul Epstein pa**********@att.net sade: TB wrote: pa**********@att.net sade: I am debugging a program to price options which involves a recursive function:
double node::get_equity(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.
Since I lack any sort of context, all I can say is that most streams
are buffered by default. That means that unless you std::flush them or
send a std::endl (not the same as a single '\n' [std::ends]) the
characters in the buffer won't be written to the connected device or io
channel. That means that your last print statement is delayed until it's
flushed or 'debug' is destroyed. That's why Stephan suggests using
std::endl at the end of a print statement.
There is also a std::clog.
TB
TB wrote: pa**********@att.net sade: TB wrote: pa**********@att.net sade: I am debugging a program to price options which involves a recursive function:
double node::get_equity(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.
Since I lack any sort of context, all I can say is that most streams are buffered by default. That means that unless you std::flush them or send a std::endl (not the same as a single '\n' [std::ends]) the characters in the buffer won't be written to the connected device or io channel. That means that your last print statement is delayed until it's flushed or 'debug' is destroyed. That's why Stephan suggests using std::endl at the end of a print statement.
There is also a std::clog.
TB
Yes, this was exactly the problem. Thanks. I didn't know the details
of these commands before. All I knew was that endl begins output on a
new line.
Paul Epstein This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Pranav |
last post by:
The Code is compiling without Error/Bug/Exception..,
What are the possibilities for this behaviour?...
|
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= ):...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...
| |