C4552: '>' : operator has no effect

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

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
  #11
Jun 16th, 2008
Originally Posted by Radical Edward View Post
> 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.
By this, do you mean what niek_e was trying to show above? he stated the following:
  1. for(;numStudents > 0; numStudents -= 1)
So basically whether you are declaring a variable or not, you must always have the semicolon? then the condition and then the counter(s) ?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,596
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: 1488
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

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

 
0
  #12
Jun 16th, 2008
>>for(numStudents; numStudents > 0; numStudents -= 1)

Or just simple this:
for( ; numStudents > 0; numStudents -= 1)

>>So basically whether you are declaring a variable or not, you must always have the semicolon? then the condition and then the counter(s) ?

Yes, there must always be two semicolons. As a minimum like this:
for( ;; )
which is the same as this:
while(true)
Last edited by Ancient Dragon; Jun 16th, 2008 at 12:46 pm.
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: 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
  #13
Jun 16th, 2008
woops never mind - saw the posting - thank you :-D
Last edited by QuantNeeds; Jun 16th, 2008 at 1:44 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



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC