delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/23/14:35:43

Date: Tue, 23 Nov 1999 16:18:46 -0300 (CDT)
From: Mitchell Cifuentes <mcifuent AT belen DOT electa DOT uta DOT cl>
To: djgpp AT delorie DOT com
Subject: Re: "for" messages
In-Reply-To: <F0458523BAB82511.F75DE6F80A0A31D6.8D4647641CEFD2ED@lp.airnews.net>
Message-ID: <Pine.OSF.3.96.991123160642.1863A-100000@belen.electa.uta.cl>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com


The problem is that the scope of a variable defined in the head of
the for loop (or other loop) is only loop itself. I read in a book
that long ago the scope extended beyond the loop. But that is not
longer true. 

On Mon, 22 Nov 1999, Rodeo Red wrote:

> This short example program from "Using C++ by Rob McGregor will not
> complile with djgpp and produces the messages below.  I assume it
> probably does compile on some other compiler so I thought you could tell
> me what's making djgpp puke.
> 
> //////////////////////////////////////////////////////
> //  Module  : array2.cpp
> //
> //  Purpose : Shows the simple usage of a
> //            one-dimensional array
> //////////////////////////////////////////////////////
> 
> #include <iostream.h>
> 
> void main()
> {
>    // Create an array of five integers
>    //
>    float num[5];
> 
>    // Iterate through the array elements, initializing
>    // them with float values
>    //
>    for (int i = 0; i < 5; i++)
>       num[i] = i * 2.25f;
> 
>    // Iterate through the array elements,
>    //   displaying their values...
> 
>    for (i = 0; i < 5; i++)
>       cout << "num[" << i <<"] == " << num[i] << '\n';
> }
> 
> 
> Produces these messages :
> 
> testfile.cpp: In function `int main(...)':
> testfile.cpp:25: name lookup of `i' changed for new ANSI `for' scoping
> testfile.cpp:19:   using obsolete binding at `i'
> 
> Line 25 is:    for (i = 0; i < 5; i++)
> Line 19 is:     for (int i = 0; i < 5; i++)
> djgpp compiler does not seem to tell me if these are error messages or
> warnings. Is there any way to tell ?
> 
> Also what are these messages trying to tell me ? I have no idea what
> they mean. How can I make this program work ?
> 
> I searched for "binding" and "scope" in the faq but didn't find
> anything.
> 
> Is there anywhere I can find a list of errors and warnings with
> explainations of what they mean ?
> 
> 
> Red
> 
> 
> --
> 
> 
> 
> 

- Raw text -


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