Here are the compiler error messages:
01926502_24.c: In function `int main(...)':
01926502_24.c:26: name lookup of `i' changed for new ANSI `for' scoping
01926502_24.c:14: using obsolete binding at `i'
what is the problem
the i problem
Moderator: Board moderators
-
- Experienced poster
- Posts: 145
- Joined: Sat Feb 23, 2002 2:00 am
- Location: Paris, France
- Contact:
I had the same problem as you, but with the following code :
[cpp]
// no i global scope variable
int main(){
// no i local scope variable
for (int i=0; i<150; i++) {
// i is only preesnt in the foor loop
// work with i;
}
printf("%d", i); // <---- HERE ! i is used but out of scope
return 0;
}
[/cpp]
The compiler sees that you're using the i defined in the for, thus trying to implicitely change its scope, wich is forbidden.
Such cases arise when you're using the for-loop to do a sequential search, and you then use the index of the found element.
To solve it, simply move int i into main()'s scope, not for(s scope.[/cpp]
[cpp]
// no i global scope variable
int main(){
// no i local scope variable
for (int i=0; i<150; i++) {
// i is only preesnt in the foor loop
// work with i;
}
printf("%d", i); // <---- HERE ! i is used but out of scope
return 0;
}
[/cpp]
The compiler sees that you're using the i defined in the for, thus trying to implicitely change its scope, wich is forbidden.
Such cases arise when you're using the for-loop to do a sequential search, and you then use the index of the found element.
To solve it, simply move int i into main()'s scope, not for(s scope.[/cpp]