Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!think!kulla!barmar
From: barmar@kulla (Barry Margolin)
Newsgroups: comp.lang.c
Subject: Re: Declaration within a loop.
Message-ID: <30174@news.Think.COM>
Date: 27 Sep 89 05:52:41 GMT
References: <2085@hydra.gatech.EDU>
Sender: news@Think.COM
Reply-To: barmar@kulla.UUCP (Barry Margolin)
Distribution: usa
Organization: Thinking Machines Corporation, Cambridge MA, USA
Lines: 19

In article <2085@hydra.gatech.EDU> dvu@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@think.com
{uunet,harvard}!think!barmar