| | |
C4552: '>' : operator has no effect
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: May 2008
Posts: 96
Reputation:
Solved Threads: 0
•
•
•
•
> 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:
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 ( for-init-statement condition(opt) ; expression(opt) ) statement
In 6.2 on page 93 you find the production for expression-statement and 7 on page 101 is the production for simple-declaration:for-init-statement: expression-statement simple-declaration
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.C++ Syntax (Toggle Plain Text)
expression-statement: expression(opt) ; simple-declaration: decl-specifier-seq(opt) init-declarator-list(opt) ;
> 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.
C++ Syntax (Toggle Plain Text)
for(;numStudents > 0; numStudents -= 1)
>>for(numStudents; numStudents > 0; numStudents -= 1)
Or just simple this:
>>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:
which is the same as this:
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.
![]() |
Similar Threads
- assign elements to a multi-d array (C)
- How to select data frm text file based on a condition (C)
- stack palindrome problem? (C++)
Other Threads in the C++ Forum
- Previous Thread: C2668: 'pow' : ambiguous call
- Next Thread: How do I make a type that recognizes brackets[] like vector?
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets



Keep reading the standard! It's good to challenge assumptions with your own interpretation and we can all learn from this kind of discussion. 



