473,769 Members | 5,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

naked func for "one-way recurrsion"

Hi all,
I have a tree object I'm writing that searches itself using a recursive
search. Thing is, I'm wanting to also include the ability to simply
transfer execution if I want ("one-way recursion"). _One problem_ with
doing it this way is stack overflow.
What I'm thinking of doing is using "naked" function calls for the
recursive search so that if I want to simply transfer execution, I could
clean up the stack myself. This seems an acceptable solution to me but, I
would be interested in other's opinions of this and of other possible
approaches.
--
Best wishes,
Allen

Jul 22 '05 #1
8 1416
On Sun, 04 Apr 2004 17:04:07 GMT in comp.lang.c++, "Allen"
<allen-terri-ngNO!@#SPAMworl dnet.att.net> wrote,
Hi all,
I have a tree object I'm writing that searches itself using a recursive
search. Thing is, I'm wanting to also include the ability to simply
transfer execution if I want ("one-way recursion"). _One problem_ with
doing it this way is stack overflow.
What I'm thinking of doing is using "naked" function calls for the
recursive search so that if I want to simply transfer execution, I could
clean up the stack myself. This seems an acceptable solution to me but, I
would be interested in other's opinions of this and of other possible
approaches.


What the heck are you talking about doing? There are quite a few terms
and phrases in your post that are unclear to me, such as
"naked function"
"transfer execution"
"one-way recursion"
"clean up stack myself"

The best way to "clean up the stack" is to return from the function.
The second best way is to throw an exception and catch it in the caller.
A very distant third is setjump/longjump, and don't even consider it.
There is no fourth way.

The whole point of having a stack is so that you can get back where you
came from. If you don't intend to return, you wouldn't use a recursive
call in the first place, but just search using a loop.

A typical case would be where you want to search for something and when
it is found stop looking. This is implemented by returning the thing
found from your recursive search, until you return to the top level,
which then uses the result or performs the desired operation upon it.

Jul 22 '05 #2
On Sun, 04 Apr 2004 17:04:07 GMT in comp.lang.c++, "Allen"
<allen-terri-ngNO!@#SPAMworl dnet.att.net> wrote,
Hi all,
I have a tree object I'm writing that searches itself using a recursive
search. Thing is, I'm wanting to also include the ability to simply
transfer execution if I want ("one-way recursion"). _One problem_ with
doing it this way is stack overflow.
What I'm thinking of doing is using "naked" function calls for the
recursive search so that if I want to simply transfer execution, I could
clean up the stack myself. This seems an acceptable solution to me but, I
would be interested in other's opinions of this and of other possible
approaches.


What the heck are you talking about doing? There are quite a few terms
and phrases in your post that are unclear to me, such as
"naked function"
"transfer execution"
"one-way recursion"
"clean up stack myself"

The best way to "clean up the stack" is to return from the function.
The second best way is to throw an exception and catch it in the caller.
A very distant third is setjump/longjump, and don't even consider it.
There is no fourth way.

The whole point of having a stack is so that you can get back where you
came from. If you don't intend to return, you wouldn't use a recursive
call in the first place, but just search using a loop.

A typical case would be where you want to search for something and when
it is found stop looking. This is implemented by returning the thing
found from your recursive search, until you return to the top level,
which then uses the result or performs the desired operation upon it.

Jul 22 '05 #3
"David Harmon" <so****@netcom. com> wrote in message
news:40******** *******@news.we st.earthlink.ne t...
On Sun, 04 Apr 2004 17:04:07 GMT in comp.lang.c++, "Allen"
<allen-terri-ngNO!@#SPAMworl dnet.att.net> wrote,
Hi all,
I have a tree object I'm writing that searches itself using a recursivesearch. Thing is, I'm wanting to also include the ability to simply
transfer execution if I want ("one-way recursion"). _One problem_ with
doing it this way is stack overflow.
What I'm thinking of doing is using "naked" function calls for the
recursive search so that if I want to simply transfer execution, I could
clean up the stack myself. This seems an acceptable solution to me but, Iwould be interested in other's opinions of this and of other possible
approaches.


What the heck are you talking about doing? There are quite a few terms
and phrases in your post that are unclear to me, such as
"naked function"
"transfer execution"
"one-way recursion"
"clean up stack myself"

The best way to "clean up the stack" is to return from the function.
The second best way is to throw an exception and catch it in the caller.
A very distant third is setjump/longjump, and don't even consider it.
There is no fourth way.

The whole point of having a stack is so that you can get back where you
came from. If you don't intend to return, you wouldn't use a recursive
call in the first place, but just search using a loop.

A typical case would be where you want to search for something and when
it is found stop looking. This is implemented by returning the thing
found from your recursive search, until you return to the top level,
which then uses the result or performs the desired operation upon it.

I looked up "naked" in my docs and found out it is platform
specific--sorry, didn't realize it was.
__declspec(nake d) causes the compiler to emit code without a
prolog/epilog allowing you to write your own in asm. What I'm wanting to do
is have a recursive function that I don't have to "un-wind" from if I don't
want to. If I decide that I don't want to return then, I need some way of
removing the return data from the stack. Ugly--I know.

Using a loop to search implies an external object acting on a data set
(doesn't it?). What I'm trying to write is a "self-searching data set" with
some "ANN-ish" ideas thrown in as well (Artificial Neural Net). I need the
ability to either search or execute code--even that's not a real good
explanation of what I'm writing.
I know I've probably butchered numerous terms and not been very clear;
this is the best I can explain without boring everyone. The question
concerns the use of naked functions in my recursive search. Obviously, I
need to be very careful handling the stack. Do you see any other specific
problems with this?
--
Best wishes,
Allen

Jul 22 '05 #4
"David Harmon" <so****@netcom. com> wrote in message
news:40******** *******@news.we st.earthlink.ne t...
On Sun, 04 Apr 2004 17:04:07 GMT in comp.lang.c++, "Allen"
<allen-terri-ngNO!@#SPAMworl dnet.att.net> wrote,
Hi all,
I have a tree object I'm writing that searches itself using a recursivesearch. Thing is, I'm wanting to also include the ability to simply
transfer execution if I want ("one-way recursion"). _One problem_ with
doing it this way is stack overflow.
What I'm thinking of doing is using "naked" function calls for the
recursive search so that if I want to simply transfer execution, I could
clean up the stack myself. This seems an acceptable solution to me but, Iwould be interested in other's opinions of this and of other possible
approaches.


What the heck are you talking about doing? There are quite a few terms
and phrases in your post that are unclear to me, such as
"naked function"
"transfer execution"
"one-way recursion"
"clean up stack myself"

The best way to "clean up the stack" is to return from the function.
The second best way is to throw an exception and catch it in the caller.
A very distant third is setjump/longjump, and don't even consider it.
There is no fourth way.

The whole point of having a stack is so that you can get back where you
came from. If you don't intend to return, you wouldn't use a recursive
call in the first place, but just search using a loop.

A typical case would be where you want to search for something and when
it is found stop looking. This is implemented by returning the thing
found from your recursive search, until you return to the top level,
which then uses the result or performs the desired operation upon it.

I looked up "naked" in my docs and found out it is platform
specific--sorry, didn't realize it was.
__declspec(nake d) causes the compiler to emit code without a
prolog/epilog allowing you to write your own in asm. What I'm wanting to do
is have a recursive function that I don't have to "un-wind" from if I don't
want to. If I decide that I don't want to return then, I need some way of
removing the return data from the stack. Ugly--I know.

Using a loop to search implies an external object acting on a data set
(doesn't it?). What I'm trying to write is a "self-searching data set" with
some "ANN-ish" ideas thrown in as well (Artificial Neural Net). I need the
ability to either search or execute code--even that's not a real good
explanation of what I'm writing.
I know I've probably butchered numerous terms and not been very clear;
this is the best I can explain without boring everyone. The question
concerns the use of naked functions in my recursive search. Obviously, I
need to be very careful handling the stack. Do you see any other specific
problems with this?
--
Best wishes,
Allen

Jul 22 '05 #5
On Sun, 04 Apr 2004 19:25:46 GMT in comp.lang.c++, "Allen"
<allen-terri-ngNO!@#SPAMworl dnet.att.net> wrote,
Using a loop to search implies an external object acting on a data set
(doesn't it?). What I'm trying to write is a "self-searching data set" with
some "ANN-ish" ideas thrown in as well (Artificial Neural Net).
No, a loop could just as easily be in a member function.
concerns the use of naked functions in my recursive search. Obviously, I
need to be very careful handling the stack. Do you see any other specific
problems with this?


Well, you asked for opinions and you've got mine: just say no. "Naked"
functions sounds like a good way for the compiler to let you implement
specific low-level necessarily platform specific things e.g. interrupt
handlers, and a really lousy thing to use in ordinary application code.

Among the great many problems with it are:
- It would be a huge effort to check for objects on the stack needing
destruction and properly call their destructors. The compiler will do
that for you. Not doing that is simply wrong.
- Murphy's law sez that as soon as you have put all that effort into
writing platform specific code, you will discover a need for a
platform-independent solution.

Returning from the function is quick and easy and I haven't heard
anything from you that suggests to me that you need anything else.
If nothing else, write it that way first and get it working.
Don't optimize before profiling.

Jul 22 '05 #6
On Sun, 04 Apr 2004 19:25:46 GMT in comp.lang.c++, "Allen"
<allen-terri-ngNO!@#SPAMworl dnet.att.net> wrote,
Using a loop to search implies an external object acting on a data set
(doesn't it?). What I'm trying to write is a "self-searching data set" with
some "ANN-ish" ideas thrown in as well (Artificial Neural Net).
No, a loop could just as easily be in a member function.
concerns the use of naked functions in my recursive search. Obviously, I
need to be very careful handling the stack. Do you see any other specific
problems with this?


Well, you asked for opinions and you've got mine: just say no. "Naked"
functions sounds like a good way for the compiler to let you implement
specific low-level necessarily platform specific things e.g. interrupt
handlers, and a really lousy thing to use in ordinary application code.

Among the great many problems with it are:
- It would be a huge effort to check for objects on the stack needing
destruction and properly call their destructors. The compiler will do
that for you. Not doing that is simply wrong.
- Murphy's law sez that as soon as you have put all that effort into
writing platform specific code, you will discover a need for a
platform-independent solution.

Returning from the function is quick and easy and I haven't heard
anything from you that suggests to me that you need anything else.
If nothing else, write it that way first and get it working.
Don't optimize before profiling.

Jul 22 '05 #7

"Allen" <allen-terri-ngNO!@#SPAMworl dnet.att.net> schrieb im
Newsbeitrag
news:be******** ************@bg tnsc04-news.ops.worldn et.att.net...
Hi all,
I have a tree object I'm writing that searches itself using a recursive search. Thing is, I'm wanting to also include the ability to simply
transfer execution if I want ("one-way recursion"). _One problem_ with doing it this way is stack overflow.


Think of this flood fill:
void Fill(long x, long y)
{
Fill(x+1, y); Fill(x, y+1); ...
}

Now, you could do this:
queue<points> have_to_fill;
have_to_fill.ad d_last(pt);
while(have_to_f ill.size())
{
fill_around_fir st_of_queue_and _append_to_last (&have_to_fill) ;
have_to_fill.re move_head();
}

Know what I mean? Use a dymanic array instead of recursion if you fear
a stack overflow.
HTH,

--
-Gernot

Post here, don't email. If you feel you have to mail, revert my
forename from:
to************* *************** **@invalid.com
_______________ _______________ __________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
Jul 22 '05 #8

"Allen" <allen-terri-ngNO!@#SPAMworl dnet.att.net> schrieb im
Newsbeitrag
news:be******** ************@bg tnsc04-news.ops.worldn et.att.net...
Hi all,
I have a tree object I'm writing that searches itself using a recursive search. Thing is, I'm wanting to also include the ability to simply
transfer execution if I want ("one-way recursion"). _One problem_ with doing it this way is stack overflow.


Think of this flood fill:
void Fill(long x, long y)
{
Fill(x+1, y); Fill(x, y+1); ...
}

Now, you could do this:
queue<points> have_to_fill;
have_to_fill.ad d_last(pt);
while(have_to_f ill.size())
{
fill_around_fir st_of_queue_and _append_to_last (&have_to_fill) ;
have_to_fill.re move_head();
}

Know what I mean? Use a dymanic array instead of recursion if you fear
a stack overflow.
HTH,

--
-Gernot

Post here, don't email. If you feel you have to mail, revert my
forename from:
to************* *************** **@invalid.com
_______________ _______________ __________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
Jul 22 '05 #9

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

Similar topics

1
2734
by: Christian Seberino | last post by:
I specify packages in my setup.py but what if I want all py files in a directory but one??? How remove just that one?? (Without listing all files I want explicitly??) I need header files to build a C extension but I DON't want headers installed. *How do I include header files in the tar.gz (tarball) file but NOT have them be installed when "python setup.py install" done??
0
1381
by: Chan | last post by:
Hi I am getting the following error when I call a web service method from .Net 2002 Application "One or more header elements marked as mustUnderstand was not understood BUT it works from .Net 2003 application Please let me know why this happens
26
3000
by: Michel Rouzic | last post by:
I have a binary file used to store the values of variables in order to use them again. I easily know whether the file exists or not, but the problem is, in case the program has been earlier interupted before it could write the variables to the file, the file is gonna be empty, and then it's gonna load a load of crap into variables, which i want to avoid. That file is always 36 bytes big (it contains 4 double-precision floats and one...
8
21912
by: Grant Richard | last post by:
Using the TcpListener and TcpClient I created a program that just sends and receives a short string - over and over again. The program is fine until it gets to around 1500 to 1800 messages. At that time, I get a SocketException with the message "Only one usage of each socket address (protocol/network address/port) is normally permitted". This happen if you use localhost or between two distinct computers. And, for a period of time after the...
3
3992
by: JohnR | last post by:
I have a form with a number of text boxes, comboboxes etc. What I would like to do is create an event handler for the "mouseenter" event for each of the controls whereby I display information about the control they just entered (sort of like an extended tooltip). Now, I can certainly create a separate mouseenter event for each control (too much work, and not very clever), but what I would like to do is somehow create one event that would...
5
3393
by: Francesc | last post by:
Hi, I'm programming some classes in order to be able to import different text formats (TXT, RTF, HTML, ...) to my own format called RUF. I've defined one Solution within several Projects, each one is focused in one specific format, includes from 5 to 15 classes and produces one DLL. Solution GATEWAY:
1
1238
by: myth.drannon | last post by:
Hi , I'm trying to find a simple solution to this question.. ( not just making two match parts) I have <xsl:template match=" one | two " > and then I want to test what match I have and do something accordinly. I was thinking <xsl:if test="match=one" > will work but it's not ....
3
10283
by: sklett | last post by:
This BUG that is so ridiculous I can't believe they shipped 05 is making my life hell. I have tried the various solutions found on the web and none of them have worked thus far. What's even more troublesome is that it appears that 05 uses these new partial classes which would makes rolling back to 03 not possible. The error I get when trying to load my Form in the designer is as follows:...
12
2049
by: spibou | last post by:
Why is a pointer allowed to point to one position past the end of an array but not to one position before the beginning of an array ? Is there any reason why the former is more useful than the later ? Spiros Bousbouras
4
1372
by: rempit | last post by:
In 1 form..have 2 "DIV".. "DIV" one is for SEARCH.. "DIV" two is for showing the RESULT from Database of "DIV" one Button.. Everything in one page.. Anyone can help me please..
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
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...
1
9994
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,...
1
7408
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
6673
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
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
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
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.