delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/24/12:16:23

From: Vik Heyndrickx <Vik DOT Heyndrickx AT rug DOT ac DOT be>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Trouble with bools
Date: Fri, 24 Oct 1997 10:55:45 +0200
Organization: University of Ghent, Belgium
Lines: 20
Message-ID: <34506291.4CB@rug.ac.be>
References: <Pine DOT SUN DOT 3 DOT 95 DOT 971021234833 DOT 12442A-100000 AT lurch-fddi>
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

H. Anthony Hoyt wrote:
> 
> Does this work
> 
> for (auto int i = 0 ; i < 640 ; i++)
>    for (auto int j = 0 ; j < 480 ; j++)
>       scrn[i][j] = 0;
> 
> What I know about "auto" is that once you are out of scope (for every new
> "i" value) "j" will be destroyed then recreated.  

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.

-- 
+----------------+
| Vik Heyndrickx |
+----------------+

- Raw text -


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