R
Ralf Goertz
Hi,
I guess I don't really understand the concept of commas as sequence
points but now I am in a position where I might have use for the comma
in a statement other than a declaration. Is the following legal:
#include <iostream>
#include <set>
using namespace std;
int main() {
set<unsigned> s;
s.insert(42);
s.insert(84);
set<unsigned>::iterator i;
for (i=s.begin(),++i;i!=s.end();++i)
cout<<*i<<endl;
return 0;
}
It compiles and does what I want, but it could still be undefined
behaviour. So is it okay to use ",++i" before the first ";" of the
for-loop, or is it saver to check for i!=s.begin() in the *body* of the
loop?
I guess I don't really understand the concept of commas as sequence
points but now I am in a position where I might have use for the comma
in a statement other than a declaration. Is the following legal:
#include <iostream>
#include <set>
using namespace std;
int main() {
set<unsigned> s;
s.insert(42);
s.insert(84);
set<unsigned>::iterator i;
for (i=s.begin(),++i;i!=s.end();++i)
cout<<*i<<endl;
return 0;
}
It compiles and does what I want, but it could still be undefined
behaviour. So is it okay to use ",++i" before the first ";" of the
for-loop, or is it saver to check for i!=s.begin() in the *body* of the
loop?