VizmayaTech





Re-entrancy in C functions

April 16th, 2006 by admin in Programming

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.

2 Responses to ' Re-entrancy in C functions '

Subscribe to comments with RSS or TrackBack to ' Re-entrancy in C functions '.

  1. girish said,
    on May 16th, 2008 at 4:56 am

    pls tell what is differecnce between recursive and reentrant funtion? ..girish_hk@yahoo.com

  2. Ritesh said,
    on February 17th, 2010 at 3:01 am

    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.

Leave a reply

:mrgreen: :neutral: :twisted: :shock: :smile: :???: :cool: :evil: :grin: :oops: :razz: :roll: :wink: :cry: :eek: :lol: :mad: :sad: