From: Vik Heyndrickx Newsgroups: comp.os.msdos.djgpp Subject: Re: Trouble with bools Date: Mon, 27 Oct 1997 08:49:44 +0100 Organization: University of Ghent, Belgium Lines: 31 Message-ID: <34544798.932@rug.ac.be> References: <34506291 DOT 4CB AT rug DOT ac DOT be> <3450C67E DOT 6DCCAF0D AT alcyone DOT com> NNTP-Posting-Host: eduserv1.rug.ac.be Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Erik Max Francis wrote: > > Vik Heyndrickx wrote: > > > > for (auto int i = 0 ; i < 640 ; i++) > > > for (auto int j = 0 ; j < 480 ; j++) > > > scrn[i][j] = 0; > > > > Conceptually, you are right. But that is not what the compiler > > effectively does. The variable j gets assigned an address and every > > instance j gets this same address. The code you get is the same when > > you would declare i and j outside the loop. > > Then you are using an old version of gcc, or are reading off an old C++ > draft standard. I was rather referening to the effectiveness of the compiler's implementation. You are completely right about the scope. But the code that generates from a routine that declares its count variables outside of the loop, *will* be the same, because the compiler's optimizer sees that actually not every time a new variable should be generated. Conceptually when you are looping the outermost loopt you get every time a new j, but the address of j will be, as a consequence, every time the same. Bye -- +----------------+ | Vik Heyndrickx | +----------------+