Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C Moderated > Re: self-call v...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 1046 of 1133
Post > Topic >>

Re: self-call vs. goto

by gordonb.6drpm@[EMAIL PROTECTED] (Gordon Burditt) Mar 8, 2008 at 12:20 PM

>I finished reading the code for the routine "count" in the C source for
>the Go playing program Wally. I downloaded it a long time ago but it
should
>be at
>http://www.usgo.org/resources/computer.html
>I know there are better programs but I'm just doing this for practice and
this
>is a fairly small program to study. The routine takes as inputs the
integer
>coordinates of a position on the board and also some parameters, one of
which
>is a board (i.e. double array of int of a certain size), called
"scratch",
>which is used to keep track of which positions have been looked at. After
>modifying the entry of scratch for the position (x,y), it then examines
the
>(up to) 4 adjacent positions and, in each case, if certain conditions are
met,
>it runs through the code for that position. Let me be more precise about
that:
>for the first 3 of the 4 possible adjacent positions, it runs through the
code
>by calling "count" with the same parameters except at this adjacent
position,
>but for the 4th it jumps to a label at the beginning of the code for
"count".
>
>So, in all 4 cases, it seems that the behavior is essentially the same.

Where does it go to *after* it has completed the calculation?  The
behavior is *not* essentially the same.  You can convert the *last*
recursive call of the form:

	return foo(some args);
into assigning the value of those args and goto the beginning of the
function.  The same is not true of recursive calls that aren't last.

In order to make the function entirely non-recursive, you'd need
to introduce a stack of positions to keep track of.  This was not
done possibly because it was viewed as (a) too complicated to bother
coding, (b) too inefficient, or (c) too difficult to maintain.

>What I'd like to know is whether there is any reason why it might be
>advantageous to use a goto in the 4th case but a self-call in the other
>three cases? Would it be better to use the goto in all 4 cases, e.g. due
>to some overhead from the function call?

If it doesn't have to work correctly, any algorithm can be done in
zero CPU time and zero bytes.
-- 
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
 -- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line.  Sorry.
 




 2 Posts in Topic:
self-call vs. goto
Allan Adler <ara@[EMAI  2008-02-17 12:05:00 
Re: self-call vs. goto
gordonb.6drpm@[EMAIL PROT  2008-03-08 12:20:01 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 1:56:00 CDT 2008.