From mboxrd@z Thu Jan 1 00:00:00 1970 From: Scott Wood Date: Wed, 08 Apr 2009 17:26:10 -0500 Subject: [U-Boot] use of C99 In-Reply-To: <49DD10BF.80002@freescale.com> References: <4A0B9AAA-4714-4C27-84A7-22FCE4D91DDA@freescale.com> <20090408192832.8D48F8560EFB@gemini.denx.de> <49DCFF1D.6080006@ge.com> <49DD0E8A.904@freescale.com> <49DD10BF.80002@freescale.com> Message-ID: <49DD2482.7040909@freescale.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Timur Tabi wrote: > Scott Wood wrote: > >> It frees the variable up for later such blocks to use. As does >> declaring iterators inside a for loop, but I guess that's forbidden as >> well. :-) > > I'm not sure whether we want to allow the same variable to be defined > more than once, even with the same type, inside a function. What's wrong with this:? for (i = 0; i < n; i++) { int j; ... } for (i = 0; i < m; i++) { int j; ... } >> Chances are it will allocate all stack space for all variables up front, >> regardless of where they're declared. > > Yes, but it many cases it won't allocate any stack space at all because > it will just keep the variable in a register. My point was that if a > variable is defined later in a function, then it's more likely to have > limited scope, so the compiler will be more likely to use a register > instead of stack to store it. I don't think it will make a difference. The compiler knows what the lifetime of the variable is, regardless of where you declare it. -Scott