Velocity Reviews > Recurssion: Why one crashes ?

# Recurssion: Why one crashes ?

codefixer@gmail.com
Guest
Posts: n/a

 09-29-2005
Hello:

I am trying to understand why one of these crash while the other works
fine.
{
if(t <= 1)
return(1);
else
}

{
if(t <= 1)
return(1);
else
}

Thanks.

Mike Wahler
Guest
Posts: n/a

 09-29-2005

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hello:
>
> I am trying to understand why one of these crash while the other works
> fine.
> {
> if(t <= 1)
> return(1);
> else

> }
>
> {
> if(t <= 1)
> return(1);
> else
> return(t * recurssion(t-1)); //works fine
> }

The expressions 't--' and 't-1' do not have the same
'pre-increment operator'.

-Mike

Peter Nilsson
Guest
Posts: n/a

 09-29-2005
Mike Wahler wrote:
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> > return(t * recurssion(t--)); //crashes

>

Both invoke undefined behaviour as they reference t for a purpose
other than to calculate it's new value prior to the next (guaranteed)
sequence point.

--
Peter

Keith Thompson
Guest
Posts: n/a

 09-29-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) writes:
> I am trying to understand why one of these crash while the other works
> fine.
> {
> if(t <= 1)
> return(1);
> else
> }
>
> {
> if(t <= 1)
> return(1);
> else
> return(t * recurssion(t-1)); //works fine
> }

Add this as the first statement of each function and try running it:

printf("Entering recurssion, t = %dl\n", t);

(BTW, the correct spelling is "recursion".)

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

Kenneth Brody
Guest
Posts: n/a

 09-29-2005
(E-Mail Removed) wrote:
>
> Hello:
>
> I am trying to understand why one of these crash while the other works
> fine.

[...]

[...]
> return(t * recurssion(t-1)); //works fine

[...]

What is the value of "t--" as compared to "t-1"?

For example, given "x = recurssion(37);", what will be the value passed
to the first recursion? What will the first pass to the second? And so
on.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <(E-Mail Removed)>