Mail Archives: djgpp/1999/11/23/06:15:09
Rodeo Red wrote:
>
> Peter Danielsson wrote:
>
> > They are only warnings and should compile anyway.
>
> The plot thickens.
> Here is the exact command I used to try to compile
>
> C:\djgpp\Source>gpp testfile.cpp -o testfile.exe
> 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'
>
> There's no testfile.exe. As far as I know, that means it didn't compile. What
> would make this happen ?
> Is the problem with the code ? or are my djfpp files corrupted ?
The code in your file used to be legal C++ code, but the final ANSI C++
standard made it illegal.
The thing to note here is that the scope of a variable declared in the
head of a loop is the rest of the head and inside of the braces:
for (/* declare variable here */; /* use it here */ ; /* use it here
*/) {
/* use it here */
}
/* can't use it here */
Your second for() loop is trying to use the 'i' declared in the head
of the first for() loop, which by the time you reached the second for()
loop has gone out of scope already.
The error messages you received from the compiler is an attempt by the
gcc authors to help users who know the old rule (which says you CAN use
the variable). Had they been less considerate, you would have received
this error message:
testfile.cpp:25: 'i' undeclared (first use in this function)
--
Weiqi Gao
weiqigao AT a DOT crl DOT com
- Raw text -