Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!uakari.primate.wisc.edu!ginosko!uunet!crdgw1!crdos1!davidsen
From: davidsen@crdos1.crd.ge.COM (Wm E Davidsen Jr)
Newsgroups: comp.lang.c
Subject: Re: Declaration within a loop.
Summary: Logical but wrong
Message-ID: <636@crdos1.crd.ge.COM>
Date: 29 Sep 89 14:44:37 GMT
References: <2085@hydra.gatech.EDU> <30174@news.Think.COM> <1199@virtech.UUCP> <3362@scolex.sco.COM>
Reply-To: davidsen@crdos1.UUCP (bill davidsen)
Distribution: usa
Organization: GE Corp R&D Center
Lines: 30

In article <3362@scolex.sco.COM>, seanf@sco.COM (Sean Fagan) writes:


|  	main() {
|  		int a;
|  		for (a=0; a< 100; a++)
|  		{
|  			int b = foo();
|  			printf ("b = %d\n", b);
|  		}
|  		return (0);
|  	}
|  
|  If 'b' is not created each time, then foo() is only called once.  However,
|  you will note that it *isn't* called just once.

  This is logical, but wrong. You are guaranteed that foo() will be
called each time through the loop, and that b will be initiallized, but
it is an implementation choice if some explicit action which could be
identified as "creating" b will be done each time or once.

  In most existing C compilers (I don't claim all) any explicit action
needed is taken once on entry to the procedure. As long as
initialization is done each time you can't tell from program behavior if
the allocation is done once or many time (not do I see any reason to care).
-- 
bill davidsen	(davidsen@crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen)
"The world is filled with fools. They blindly follow their so-called
'reason' in the face of the church and common sense. Any fool can see
that the world is flat!" - anon