LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-06-2005, 04:19 PM   #1
lmvent
LQ Newbie
 
Registered: Sep 2005
Posts: 24

Rep: Reputation: 15
obsolete binding??


Here is my code:




#include <iostream>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(void)
{ int atHome = 0;
int stepsToTry = 5000;
double x = 0;
double y = 0;
double dx = 0;
double dy = 0;
double angle;
const double PI = 4*atan(1.0);
cout << "Will Waldo make it home?\n\n";
cout << "Input an int to start the random number generator: ";
int myStart;
cin >> myStart;
srand(myStart);
for (int i = 0; i < stepsToTry; i = i + 1)
{ rand();
do
{ double angle = 2*PI*rand()/RAND_MAX;
dx = cos(angle);
dy = sin(angle);
}while (atHome = 0);
do
{ y = y + dy;
}while (y >= -10 && y <= 10);
do
{ x = x + dx;
}while (x >= -10 && x <= 10);
if (x>=8 && x<=10)
{ if(y >= 8 && y <= 10)
{ atHome = 1;
}
}
}
if (atHome)
{ cout << "Waldo made it home after taking " << i << "steps!\n";
}
else
{ cout << "Waldo is still lost after taking" << stepsToTry << "steps\n\n";
cout << "Please play again and try to get Waldo home!\n";
}
return 0;
}


Here is my error:



waldo.cpp: In function 'int main()':
waldo.cpp:41: name lookup of 'i' changed for new ISO 'for' scoping
waldo.cpp:21: using obsolete binding at 'i'


What the hell does that mean?
 
Old 10-06-2005, 05:03 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
When posting code, please, please, please use code tags around it. If you don't know what the code tags are, there is a button labeled "Code" above the message reply/new thread text box. Click it and it will insert the tags for you.

Your problem lies with scoping. The only place your code declares the variable is inside a for-loop:
Code:
 for (int i = 0; i < stepsToTry; i = i + 1)
You later reference it outside the for loop with:
Code:
cout << "Waldo made it home after taking " << i << "steps!\n";
When declaring a variable like this, it only exists inside the for-loop. Some compilers accepted sloppy programming by letting the variable get referenced outside its scope. The warning you get from g++ says that the ISO standard now explicitly disallows use outside the for loop. The compiler will continue compiling the code by assuming the sloppy method should be used.

Either declare the variable outside the for loop, or reference a different variable in the cout statement to avoid the message.

Also, you have a mistake in one of your do-while loops:
Code:
 do
{
  double angle = 2*PI*rand()/RAND_MAX;
  dx = cos(angle);
  dy = sin(angle);
}while (atHome = 0);
The text in red is an assignment not a comparison. That expression will always assign 0 to atHome and the expression will always evaluate to false.
 
1 members found this post helpful.
Old 12-02-2010, 07:15 PM   #3
frogn8r
LQ Newbie
 
Registered: Dec 2010
Posts: 1

Rep: Reputation: 0
Talking obsolete binding??

I was just faced with this weird anomaly also. Turns out I was accidentally adding the semicolon to the end of my for loop statement.
e.g.
Code:
 for (int count = 0; count <= sumNum; ++count);
It's the newbie mistake of the semicolon at the end that threw me off.
I'm sure this would effect all types of loops, including (but not limited too) While loops, Do loops, and maybe even if-else statement.

Hope this helps.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Obsolete version required... andrei_t Fedora 10 07-08-2005 05:19 AM
M$ Doz obsolete? witeshark General 11 02-07-2004 06:45 PM
Is Microsoft Obsolete? GtkUser General 24 07-24-2003 07:34 PM
What's up with iostream.h, is it obsolete? linuxlah Programming 4 02-04-2003 05:29 AM
Removing Obsolete Software JHuizingh Linux - General 4 02-26-2002 02:17 PM


All times are GMT -5. The time now is 10:54 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration