The C programming language allows re-entrant subroutines. The stack-based implementation of the subroutine allows each invocation of the subroutine to obtain a new stack frame and new set of local variables. To make a subroutine (function) in C re-entrant, following should be satisfied:
· The function should not hold or refer to any static data. Static data is non-stack data that is statically located for the lifetime of the program. Any function that refers to static data would refer to the same copy, and can potentially step on each other if the function is concurrently executed.
· The function should not call any other non-reentrant functions. This seems like an obvious requirement, but it needs special attention since reentrancy of a library function can easily get overlooked. For e.g., the library function ctime returns a character pointer, and invocation of ctime can make a function non-reentrant.
· The function should not return a pointer to static data.
pls tell what is differecnce between recursive and reentrant funtion? ..girish_hk@yahoo.com
Any recursive function must be reentrant, because each instance of its execution must have its own set of local variables to avoid corrupting any other instance. Reentrancy is a desired property of a recursive function.