Declaration within a loop.

Conor P. Cahill cpcahil at virtech.UUCP
Thu Sep 28 12:41:08 AEST 1989


In article <1989Sep27.185904.18985 at jarvis.csri.toronto.edu>, flaps at dgp.toronto.edu (Alan J Rosenthal) writes:
> This statement is blatantly false (about anything about C).  It confuses
> implementation with definition.  To re-use the same variable cell each time
> through the loop is a valid implementation of deallocating it and reallocating
> it each time through the loop, because deallocating and allocating are inverse
> operations.  This doesn't mean that the meaning of declaring a variable inside
> a loop in C is that it is allocated upon function entry.

I did not say that a variable declared within a loop is allocated upon 
function entry.  I said that it is not re-allocated throughout every iteration
of the loop.  The variable is "active" throughout the entire lifetime of the 
loop.  However, if the variable is initialized, it will be reinitialized 
each time through the loop.

In thinking about it a bit more since my original response I would have
to say that while this may be the behavior in any "sane" implementation,
it would not be prudent to have any expectations as to the value stored 
in the data area through each iteration of the loop.
-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+



More information about the Comp.lang.c mailing list