The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help Help Help in recursion murtaza Shell Programming and Scripting 6 03-29-2007 10:26 AM
A Question On Recursion In Ksh marlonus999 Shell Programming and Scripting 1 01-11-2007 07:09 AM
allow recursion on dns server? xnightcrawl UNIX for Advanced & Expert Users 1 03-29-2006 10:36 AM
recursion too deep swamy455 Shell Programming and Scripting 3 07-18-2005 03:18 PM
recursion gsjf Shell Programming and Scripting 1 08-26-2002 12:22 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 3.00 average. Display Modes
  #1 (permalink)  
Old 12-02-2008
joshighanshyam joshighanshyam is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 14
Recursion

I want to halt a tail recursive function after certain validation. I want to come out of entire recursion without unwinding phase. How can i achieve that . The coding is done in C language.
  #2 (permalink)  
Old 12-02-2008
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by joshighanshyam View Post
I want to halt a tail recursive function after certain validation. I want to come out of entire recursion without unwinding phase. How can i achieve that . The coding is done in C language.
Is there any reason you are not taking the iterative approach ?
  #3 (permalink)  
Old 12-02-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,884
You've been around long enough not to post homework questions, so I'll answer: use setjmp() and longjmp(). Basically, the first call saves the current stack configuration (stack pointer, parent caller address, etc). The second call restores that stack configuration. So you might have some code like this:
Code:
#include <setjmp.h>
int found = 0;
jmp_buf origin; 
main() {
  setjmp(&origin);
  if (found == 0) 
     recursive_call();
}

recursive_call() {

   /* HERE: set found to 1 at some point */
   /* then... */
   if (found == 0) 
      recursive_call();
   else 
      longjmp( &origin );
}
  #4 (permalink)  
Old 12-03-2008
esther.david6 esther.david6 is offline
Banned
  
 

Join Date: Nov 2008
Posts: 6
what is recursive?

A procedure that is applied once, and then applied to the result of that application, and so on. A recursive definition defines the result of some operation for 0, and then the result for any number n + 1 in terms of the result for n; thus the operation becomes defined for all numbers (the notion may be extended to describe the same process on any well-ordered set).
  #5 (permalink)  
Old 12-03-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,884
Esther/Daid, I don't think the user wants to know WHAT a recursive procedure is. He wants to know how to exit the procedure while skipping all the returns and function clean-up.
  #6 (permalink)  
Old 12-03-2008
joshighanshyam joshighanshyam is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 14
Thanks you all for your valuable Feedbacks
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0