delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/28/08:45:23

From: Vik Heyndrickx <Vik DOT Heyndrickx AT rug DOT ac DOT be>
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: <Pine DOT SUN DOT 3 DOT 95 DOT 971021234833 DOT 12442A-100000 AT lurch-fddi> <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
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 |
+----------------+

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019