Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: C++ coding standards (Comment needed) Keywords: standard,variables Message-ID: <56642@microsoft.UUCP> Date: 16 Aug 90 20:01:09 GMT References: <2161@runxtsa.runx.oz.au> <1990Aug13.182226.24141@alias.uucp> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 19 In article <1990Aug13.182226.24141@alias.uucp> bmcphers@alias.UUCP (Brent McPherson) writes: >Finally, common sense should prevail. If a variable is first assigned a value >within a loop it should be declared outside the loop just in case the compiler >decides to create the variable on the stack for each loop iteration. Hm, I'm not sure I understand what you're trying to say here. In the following code: for (int i=0; i<1000; ++i) { FOO foo(i); foo.DoSomething(); } It is certainly not the case that a thousand foos reside simultaneously on the stack. Rather, it is guaranteed that an object is destroyed as its constructor is jumped back over. Thus, while conceptually there are a 1000 foos, only one is in existance at any point in time, and they all reside at the same location on the stack.