C4552: '>' : operator has no effect

Thread Solved
Reply

Join Date: May 2008
Posts: 96
Reputation: QuantNeeds is an unknown quantity at this point 
Solved Threads: 0
QuantNeeds QuantNeeds is offline Offline
Junior Poster in Training

C4552: '>' : operator has no effect

 
0
  #1
Jun 16th, 2008
Help – for both of my for header components, error reads the following, but I do not understand how to fix this because I am not sure what is wrong about it. Please help.

warning C4552: '>' : operator has no effect; expected operator with side-effect



  1.  
  2. void inputGrades (int numStudents,int numGrades)
  3. {
  4. for(numStudents > 0; numStudents -= 1;)
  5. {
  6. cout << "For this student enter the grades.";
  7. double score = 0;
  8. double grade, avg;
  9.  
  10. int exams = numGrades;
  11. for(exams > 0; exams -= 1;)
  12. {
  13. cout << "Grade: ";
  14. cin >> grade;
  15. score += grade;
  16. }
  17.  
  18. avg = static_cast<double>(score) / numGrades;
  19. cout << "The average test score for the student is: " << avg << endl;
  20. }
  21. }
  22.  
  23. int main()
  24. {
  25. int students, tests;
  26.  
  27. cout << "Enter the number of students: ";
  28. cin >> students;
  29. cout << "Enter the number of tests: ";
  30. cin >> tests;
  31.  
  32. inputGrades(students, tests);
  33.  
  34. cout << endl;
  35. return 0;
  36.  
  37. } // end main
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: C4552: '>' : operator has no effect

 
0
  #2
Jun 16th, 2008
Odd, I'm not getting that error at all...

Did you include the preprocessor directives for cstdlib and iostream? Also are you using namespace std?

It ran fine for me, no weird operator errors.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 9
Reputation: TacklesMcCaw is an unknown quantity at this point 
Solved Threads: 2
TacklesMcCaw TacklesMcCaw is offline Offline
Newbie Poster

Re: C4552: '>' : operator has no effect

 
0
  #3
Jun 16th, 2008
Originally Posted by QuantNeeds View Post



  1.  
  2. for(numStudents > 0; numStudents -= 1;)
Generally it's good form to declare the variables used in the for loop, like:

  1. for (numStudents; numStudents > 0; numStudents--)

I don't know if the compiler considers what you've done an error, but it might, I've never actually tried it anyway besides the three section for declaration above. That might be your problem. Also, is your compiler just spitting out a warning or an error, they're different.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 296
Reputation: tesuji is on a distinguished road 
Solved Threads: 42
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: C4552: '>' : operator has no effect

 
0
  #4
Jun 16th, 2008
Hi QuantNeeds
Originally Posted by QuantNeeds View Post
. . .
warning C4552: '>' : operator has no effect; expected operator with side-effect
. . .
  1. int numStudents = 10; // assignment necessary
  2. for(numStudents > 0; numStudents -= 1;)
Your for loop is correct. It corresponds completely with the Standard ISO/IEC 14882:1998(E) of C++. So your compiler seems to be something outdated, especially the phrase "expected operator with side-effect", what means that an for-init statement would have been expected, tells that your compiler isn't that conform to the standard.

brs,
tesu
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,752
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 294
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Posting Maven

Re: C4552: '>' : operator has no effect

 
0
  #5
Jun 16th, 2008
Originally Posted by tesuji View Post
Hi QuantNeeds

Your for loop is correct.
No it's not, TacklesMcCaw is right. There's a semicolon in the wrong place:
this: for(numStudents > 0; numStudents -= 1;)
Should be this: for(;numStudents > 0; numStudents -= 1)

same goes for for(exams > 0; exams -= 1;) ; this should be for(;exams > 0; exams -= 1)

Originally Posted by tesuji View Post
So your compiler seems to be something outdated, especially the phrase "expected operator with side-effect", what means that an for-init statement would have been expected, tells that your compiler isn't that conform to the standard.
VS2008 pro will give you the exact same warning-message and I wouldn't call that compiler 'outdated'. The code will compile, but a warning is given to indicate that although the code is 'correct' the user probably made an error.
Last edited by niek_e; Jun 16th, 2008 at 6:50 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 296
Reputation: tesuji is on a distinguished road 
Solved Threads: 42
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: C4552: '>' : operator has no effect

 
1
  #6
Jun 16th, 2008
Hi niek_e

You are right, I have overlooked the semicolon at he far right.

Intuitively I also would put a semicolon at left side if for-init statement is off. But the ISO standard tells the opposite. You may have a look at this standard on http://www-d0.fnal.gov/~dladams/cxx_standard.pdf
In the lower half page 95 you will find the definition of the for-loop. Where
you can see that the first semicolon is integral part of the for-init statement,
just consider the gap between for-init statement and condition statement, also see
the given note. That means, if one omits the for-init statement the semicolon also
disappears.

Obviously, almost all C++ compilers do not implement the for loop in concordance with the ISO Standard, do they?

krs,
tesu
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,752
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 294
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Posting Maven

Re: C4552: '>' : operator has no effect

 
0
  #7
Jun 16th, 2008
Originally Posted by tesuji View Post
In the lower half page 95 you will find the definition of the for-loop. Where
you can see that the first semicolon is integral part of the for-init statement,
just consider the gap between for-init statement and condition statement, also see
the given note. That means, if one omits the for-init statement the semicolon also
disappears.
I've read it and it appears you're right, but I've never seen a compiler that will compile this:
  1. int a = 0;
  2. for (a<50;a++)
Originally Posted by tesuji View Post
Obviously, almost all C++ compilers do not implement the for loop in concordance with the ISO Standard, do they?
Apparently not
Last edited by niek_e; Jun 16th, 2008 at 9:11 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,142
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1434
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: C4552: '>' : operator has no effect

 
0
  #8
Jun 16th, 2008
The for statement is actually explained on page 97. paragraph 6.5.3.3 shows the correct syntax. Without doing any research I'll bet there has been a later correction to 6.5.3.1 and what was shown at the botton of page 95.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 351
Reputation: Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about 
Solved Threads: 62
Radical Edward's Avatar
Radical Edward Radical Edward is offline Offline
Posting Whiz

Re: C4552: '>' : operator has no effect

 
1
  #9
Jun 16th, 2008
> That means, if one omits the for-init statement the semicolon also disappears.
That's not quite right, but Edward can easily see why you'd think that. Like most stuff in the standard, you have to look in several different places to get the whole picture. Specifically, the syntax for a for loop is:
for ( for-init-statement condition(opt) ; expression(opt) ) statement
The first semicolon is missing because it's implied to always exist. You can see that if you follow the production for for-init-statement:
for-init-statement:
        expression-statement
        simple-declaration
In 6.2 on page 93 you find the production for expression-statement and 7 on page 101 is the production for simple-declaration:
  1. expression-statement:
  2. expression(opt) ;
  3.  
  4. simple-declaration:
  5. decl-specifier-seq(opt) init-declarator-list(opt) ;
The semicolon isn't optional in expression-statement or simple-declaration, and for-init-statement isn't optional either. This means that a semicolon is always required, even if the for-init-statement is otherwise empty.

> Obviously, almost all C++ compilers do not implement the for loop in concordance with the ISO Standard, do they?
It's not obvious to be sure, but almost all compilers seem to get it right. Keep reading the standard! It's good to challenge assumptions with your own interpretation and we can all learn from this kind of discussion.
Last edited by Radical Edward; Jun 16th, 2008 at 10:24 am.
If at first you don't succeed, keep on sucking until you do succeed.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 96
Reputation: QuantNeeds is an unknown quantity at this point 
Solved Threads: 0
QuantNeeds QuantNeeds is offline Offline
Junior Poster in Training

Re: C4552: '>' : operator has no effect

 
0
  #10
Jun 16th, 2008
This was the quickest solution that helped. This is what I changed it to:

  1.  
  2. for(numStudents; numStudents > 0; numStudents -= 1)
  3. {
  4. double score = 0;
  5. double grade, avg;
  6.  
  7. for(int exams = numGrades; exams > 0; exams -= 1)
  8. {
  9. cout << "Grade: ";
  10. cin >> grade;
  11. score += grade;
  12. }

Originally Posted by TacklesMcCaw View Post
Generally it's good form to declare the variables used in the for loop, like:

  1. for (numStudents; numStudents > 0; numStudents--)

I don't know if the compiler considers what you've done an error, but it might, I've never actually tried it anyway besides the three section for declaration above. That might be your problem. Also, is your compiler just spitting out a warning or an error, they're different.
Last edited by QuantNeeds; Jun 16th, 2008 at 12:39 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC