473,503 Members | 3,884 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 1756
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.remcomp.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********@maineline.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
--
"Consideration 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********@maineline.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,&local);

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********@maineline.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,&local);

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 (terminationCondition( x ))
{
return dependsOnUplinkChainAndX( 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***********************@news.orange.fr>,
jacob navia <ja***@jacob.remcomp.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,&local);

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
--
"Consideration 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********@maineline.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,&local);

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 (terminationCondition( x ))
{
return dependsOnUplinkChainAndX( 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***********************@news.orange.fr>,
jacob navia <ja***@jacob.remcomp.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,&local);

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
3052
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...
44
3211
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
1884
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...
19
2259
by: Kay Schluehr | last post by:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691
11
3907
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...
4
1449
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...
35
4682
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
2041
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...
0
7063
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...
0
7258
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,...
0
7313
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...
1
6970
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...
0
7441
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...
0
4663
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...
0
3156
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...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
366
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...

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.