calling function recursively, local variables? 
Author Message
 calling function recursively, local variables?

Hi all,

 Sending this one out to anyone that can help.  I am calling a function
from within itself and want to know what is going to happen to the value
of my local variables.  I need them to be different for each instance of
the function.  I could give them the thread attribute, but that would
require that I START the function on it's own thread, which I thought
was not allowed.  Am I correct? Suggestions?

Geoff Erickson
Developer
Agricom



Tue, 04 Jul 2000 03:00:00 GMT  
 calling function recursively, local variables?

Just declare without any attributes (the STATIC attribute will allow the
variable be visible to all instances of the procedure) e.g.

Factorial    procedure(long n)

LocVar    long

  code
  LocVar = n - 1
  if LocVar <= 1
    return(1)
  end
  return(Factorial(LocVar))

Gordon.

Quote:

>Hi all,

> Sending this one out to anyone that can help.  I am calling a function
>from within itself and want to know what is going to happen to the value
>of my local variables.  I need them to be different for each instance of
>the function.  I could give them the thread attribute, but that would
>require that I START the function on it's own thread, which I thought
>was not allowed.  Am I correct? Suggestions?

>Geoff Erickson
>Developer
>Agricom



Tue, 04 Jul 2000 03:00:00 GMT  
 calling function recursively, local variables?

Hi Geoff,



Quote:
> Sending this one out to anyone that can help.  I am calling a function
>from within itself and want to know what is going to happen to the value
>of my local variables.  I need them to be different for each instance of

Recursive stuff always makes my head spin<g> but I think that
variables would be only within the scope of each instance of the
procedure.

Best regards,

Arnor Baldvinsson
Allerup Edb
Tel: +45 4675 7122
Fax: +45 4675 7144
Denmark


http://www.icetips.com
UIN nr.: 2428601



Tue, 04 Jul 2000 03:00:00 GMT  
 calling function recursively, local variables?



Quote:
> Hi Geoff,



> > Sending this one out to anyone that can help.  I am calling a function
> >from within itself and want to know what is going to happen to the value
> >of my local variables.  I need them to be different for each instance of

> Recursive stuff always makes my head spin<g> but I think that
> variables would be only within the scope of each instance of the
> procedure.

As long as they're not STATIC.

--
For Hire,
Tom Ruby
Industry, Illinois USA
http://www.netins.net/showcase/tomruby/
CW Resource Page -> http://www.netins.net/showcase/tomruby/clarion/



Tue, 04 Jul 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Local variables, call-back functions under Windows

2. Calling a lambda function inside a let block recursively

3. local variable and local variable in block behave differently

4. indirect function calls and variable variables

5. indirect function calls and variable variables

6. local variables in functions

7. nasm , functions and local variables

8. NASM - how do I define local variables in a function

9. global variables and local functions.

10. local variable not destructed if the function raised a exception

11. VC++ calling fortran function and fortran function calling a c++ function

12. Calling local functions from the C API

 

 
Powered by phpBB® Forum Software