473,804 Members | 3,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

does CCS supports tail recursion?

hi all,

I m new joiny.
I read that most of the compiler auto detect tail recursion in
program. can any body tell me that is Code compoaser studio for TI dsp
supports?

rgds,

Aug 5 '07 #1
9 1772
shailesh wrote:
hi all,

I m new joiny.
I read that most of the compiler auto detect tail recursion in
program. can any body tell me that is Code compoaser studio for TI dsp
supports?
Try one of their support forums, your question is OT here.

--
Ian Collins.
Aug 5 '07 #2
shailesh wrote:
hi all,

I m new joiny.
I read that most of the compiler auto detect tail recursion in
program. can any body tell me that is Code compoaser studio for TI dsp
supports?

rgds,
I suppose that if you write:

int main(void)
{
return main();
}

You will have an infinite loop if it DOES support
tail recursion, a stack fault (trap) if it doesn't...

P.S. Maybe the processor you are using doesn't have any
memory protection. In that case use a printf statement
before the call to main to see if there is other kind of problem.

#include <stdio.h>
int main(void)
{
printf("ignore this\n");
return main();
}

An infinite loop will look different than a stack overflow with
this setup.
Aug 5 '07 #3
On Aug 5, 3:35 pm, jacob navia <ja...@jacob.re mcomp.frwrote:
shailesh wrote:
hi all,
I m new joiny.
I read that most of the compiler auto detect tail recursion in
program. can any body tell me that is Code compoaser studio for TI dsp
supports?
rgds,

I suppose that if you write:

int main(void)
{
return main();

}

You will have an infinite loop if it DOES support
tail recursion, a stack fault (trap) if it doesn't...

P.S. Maybe the processor you are using doesn't have any
memory protection. In that case use a printf statement
before the call to main to see if there is other kind of problem.

#include <stdio.h>
int main(void)
{
printf("ignore this\n");
return main();

}

An infinite loop will look different than a stack overflow with
this setup.
thanks Jacob,
I could find out it using ur suggession.:)
It does not support:(

Aug 5 '07 #4
In article <46************ ***@yahoo.com>,
CBFalconer <cb********@mai neline.netwrote :
>Whenever the last action of the routine is to call itself with
revised parameters, this can obviously be replaced by a loop.
Not necessarily. For example, consider the case where the address
of a local variable is passed.

And of course self-call is just the simplest example of tail call.

-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Aug 6 '07 #5
Richard Tobin wrote:
In article <46************ ***@yahoo.com>,
CBFalconer <cb********@mai neline.netwrote :
>Whenever the last action of the routine is to call itself with
revised parameters, this can obviously be replaced by a loop.

Not necessarily. For example, consider the case where the address
of a local variable is passed.

And of course self-call is just the simplest example of tail call.

-- Richard
Why would it matter?

suppose that as the last action you make
return sameproc(2,3,&l ocal);

Since the value of "local" can't ever be used after
the call returns, it doesn't matter at all.

jacob
Aug 6 '07 #6
jacob navia wrote:
Richard Tobin wrote:
>In article <46************ ***@yahoo.com>,
CBFalconer <cb********@mai neline.netwrote :
>>Whenever the last action of the routine is to call itself with
revised parameters, this can obviously be replaced by a loop.

Not necessarily. For example, consider the case where the address
of a local variable is passed.

And of course self-call is just the simplest example of tail call.

-- Richard

Why would it matter?

suppose that as the last action you make
return sameproc(2,3,&l ocal);

Since the value of "local" can't ever be used after
the call returns, it doesn't matter at all.
I'm afraid you are mistaken, since the address of `local` can be used
/inside the call of `sameproc`/. Hence it's important that `local`
continue to exist, hence (in the usual implementation) that the
stack frame it's in continues to exist, hence you can't do the
straightforward stack-frame elimination part of tail-call optimisation.

Consider this horrible sketch of an example:

Answer example( Args x, struct Ex *uplink )
{
if (terminationCon dition( x ))
{
return dependsOnUplink ChainAndX( x, uplink );
}
else
{
struct Ex another;
another.uplink = uplink;
another.stuff = hackeryOn( x );
return example( shrink( x ), &another );
}
}

The recursive call can't be TCOd; the number of `another` elements
needed depends on how much `x` needs to be shrunk before meeting
the termination condition, so you can't junk the stack frames.

--
Chris "tails can't speak, never mind /call/." Dollin

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

Aug 6 '07 #7
In article <46************ ***********@new s.orange.fr>,
jacob navia <ja***@jacob.re mcomp.frwrote:
>Not necessarily. For example, consider the case where the address
of a local variable is passed.
>Why would it matter?

suppose that as the last action you make
return sameproc(2,3,&l ocal);

Since the value of "local" can't ever be used after
the call returns, it doesn't matter at all.
The second activation of sameproc needs to have its own version of
"local" which is distinct from the one in the first activation.

For example, you could build a linked list out of stack-allocated cons
cells (though of course you couldn't return it). More realistically,
you might have local structures representing some kind of environment
that contain a pointer to the passed-in parent environment.

-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Aug 6 '07 #8
Chris Dollin wrote:
jacob navia wrote:
>Richard Tobin wrote:
>>In article <46************ ***@yahoo.com>,
CBFalconer <cb********@mai neline.netwrote :

Whenever the last action of the routine is to call itself with
revised parameters, this can obviously be replaced by a loop.
Not necessarily. For example, consider the case where the address
of a local variable is passed.

And of course self-call is just the simplest example of tail call.

-- Richard
Why would it matter?

suppose that as the last action you make
return sameproc(2,3,&l ocal);

Since the value of "local" can't ever be used after
the call returns, it doesn't matter at all.

I'm afraid you are mistaken, since the address of `local` can be used
/inside the call of `sameproc`/. Hence it's important that `local`
continue to exist, hence (in the usual implementation) that the
stack frame it's in continues to exist, hence you can't do the
straightforward stack-frame elimination part of tail-call optimisation.

Consider this horrible sketch of an example:

Answer example( Args x, struct Ex *uplink )
{
if (terminationCon dition( x ))
{
return dependsOnUplink ChainAndX( x, uplink );
}
else
{
struct Ex another;
another.uplink = uplink;
another.stuff = hackeryOn( x );
return example( shrink( x ), &another );
}
}

The recursive call can't be TCOd; the number of `another` elements
needed depends on how much `x` needs to be shrunk before meeting
the termination condition, so you can't junk the stack frames.
Thanks, I see now. Will remember next time I try to implement
that optimization. I have considered doing it, but never got into
that.

Aug 6 '07 #9
Richard Tobin wrote:
In article <46************ ***********@new s.orange.fr>,
jacob navia <ja***@jacob.re mcomp.frwrote:
>>Not necessarily. For example, consider the case where the address
of a local variable is passed.
>Why would it matter?

suppose that as the last action you make
return sameproc(2,3,&l ocal);

Since the value of "local" can't ever be used after
the call returns, it doesn't matter at all.

The second activation of sameproc needs to have its own version of
"local" which is distinct from the one in the first activation.

For example, you could build a linked list out of stack-allocated cons
cells (though of course you couldn't return it). More realistically,
you might have local structures representing some kind of environment
that contain a pointer to the passed-in parent environment.

-- Richard
Thanks, I did not see that possibility.

jacob
Aug 6 '07 #10

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

Similar topics

10
3078
by: Christopher T King | last post by:
Is it feasable, and/or desirable to have Python optimize tail-recursive calls, similar to Scheme and gcc -O2? i.e. effectively compile this: def foo(n): return foo(n-1) into this: def foo(n): goto foo(n-1)
44
3287
by: Bamber | last post by:
Why does f get returned ? (compiled with gcc). #include<stdio.h> int func(int a); main() { int f; f=func(7); printf("f=%d",f);
0
1897
by: Ray Wesley Kinserlow Jr. | last post by:
We have been studying tail recursion in my computer class. The prof told us that some compilers will turn a tail recursion into an iteration thus allowing many, many function calls to the recursion. I have proved to myself that the two flavors of VC++ I have will do this but I cannot get the GNU G++ compiler to do so. It is run in unix on a sun sparc and is version 3.3.2. It's threading is POSIX. Is there a switch which will compile a...
19
2289
by: Kay Schluehr | last post by:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691
11
3932
by: Josiah Manson | last post by:
In the following program I am trying to learn how to use functional programming aspects of python, but the following program will crash, claiming that the recursion depth is too great. I am attempting to make a list of polynomial functions such that poly(3) = 1, poly(3) = 3, poly(3) = 9, etc. Could someone point me in the right direction? Thanks. def make_polys(n): """Make a list of polynomial functions up to order n. """
4
1475
by: ssecorp | last post by:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691 so I try it and when I run: @Decorators.tail_recursion def fibtr(n): def fibt(a, b, n): if n <= 1: return b else: return fibt(b, a + b, n - 1)
35
4744
by: Muzammil | last post by:
int harmonic(int n) { if (n=1) { return 1; } else { return harmonic(n-1)+1/n; } } can any help me ??
3
2050
by: not_a_commie | last post by:
A tail call is a way of removing the current method from the stack before recursing. See http://blogs.msdn.com/shrib/archive/2005/01/25/360370.aspx .. I would love to see it in C# 4.0 and wouldn't mind if we needed a special keyword to make it happen.
0
9706
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
9584
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,...
1
10323
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
10082
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
9160
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
7622
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
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5654
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.