Declaration within a loop.

Barry Margolin barmar at kulla
Wed Sep 27 15:52:41 AEST 1989


In article <2085 at hydra.gatech.EDU> dvu at prism.gatech.EDU (Dinh Vu) writes:
>     do {
>		 int i;
>		 ........ ;
>     } while (1);
>Is it true that every time through the loop, a new i variable
>is declared (more memory allocated ??)?  

Yes, a new i variable is declared.  However, at the end of each time
through the loop it is "undeclared", so it can be deallocated.  Most C
implementations will actually use the same memory location (probably
on the stack) each time.  And since C isn't required to zero automatic
variables, it will probably even have the same value as it had in the
previous iteration; however, any program that tries to take advantage
of this is pretty disgusting, in my opinion.
Barry Margolin, Thinking Machines Corp.

barmar at think.com
{uunet,harvard}!think!barmar



More information about the Comp.lang.c mailing list