473,394 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

++i++ for iterator in loops (gcc-3.4.4)

Hi,

i stumbled this in source code review:

VALID(?!):
======

frank@frank-desktop:~$ cat test.cc
#include <iostream>
#include <list>

int main()
{
std::list<intvalues;
values.push_back(1);
values.push_back(2);
values.push_back(3);
values.push_back(4);
values.push_back(5);
values.push_back(6);
for (std::list<int>::const_iterator i = values.begin();
i != values.end();
++i++) { // ### SEE THIS
std::cout << "i is " << *i << std::endl;
}
return 0;
}

frank@frank-desktop:~$ ./test
i is 1
i is 2
i is 3
i is 4
i is 5
i is 6
NOT VALID:
=======

frank@frank-desktop:~$ cat test.cc
#include <iostream>
#include <list>

int main()
{
for (int i = 1;
i < 7;
++i++) {
std::cout << "i is " << i << std::endl;
}
return 0;
}

doesn't compile:

frank@frank-desktop:~$ g++ -o test test.cc
test.cc: In function »int main()«:
test.cc:8: Fehler: Ungültiger L-Wert in Erhöhung

So why behaves iterator different that integer?

rgds

Frank
Feb 6 '08 #1
1 1355
Frank Bergemann wrote:
Hi,

i stumbled this in source code review:

VALID(?!):

It's undefined behavior for integers.
It's possibly undefined behavior for iterators, but
certainly something that you can't rely on being well
defined.

What is it supposed to do anyhow.

++i, ++i

would be well defined and clearer in intent.
Feb 6 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
by: Grant Edwards | last post by:
In an interview at http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=273 Alan Kay said something I really liked, and I think it applies equally well to Python as well as the languages...
15
by: JustSomeGuy | last post by:
I have a need to make an applicaiton that uses a variable number of nested for loops. for now I'm using a fixed number: for (z=0; z < Z; ++z) for (y=0; y < Y; ++y) for (x=0; x < X; ++x)
9
by: Harald Grossauer | last post by:
Usually STL containers have something like "iterator container<>::erase(iterator)" which erases the element the iterator points to and returns another valid iterator. Set does not have this,...
2
by: James Ying | last post by:
Following is the complete code demonstrating the issue: ===================== > cat tt.cc #include <iostream> template <class T> class Base { public: typedef T difference_type; };
13
by: Adam Hartshorne | last post by:
Hi All, I was wondering if anybody can tell me what is wrong with the following code, in a .h file I have std::list<std::vector<Site> > positions ; std::list<std::vector<Site> >::iterator...
17
by: John Salerno | last post by:
I'm reading Text Processing in Python right now and I came across a comment that is helping me to see for loops in a new light. I think because I'm used to the C-style for loop where you create a...
18
by: silversurfer | last post by:
Ok, this should be fairly easy for most of you (at least I hope so), but not for me: Let us say we have got the following elements: std::vector<Entry> models; //Entry is a struct...
22
by: =?gb2312?B?wNbA1rTzzOzKpg==?= | last post by:
windows xp, visual studio 2005 ---------------------------------------------------------------------------------------------------------------------------------- #include <iostream> #include <map>...
3
by: Alex__655321 | last post by:
Hello All I hope I'm correct posting an STL question here - if not feel free to direct me to somewhere more appropriate. I'm writing some code using an std::set which I believe is the best...
50
by: John Salerno | last post by:
I know it's popular and very handy, but I'm curious if there are purists out there who think that using something like: for x in range(10): #do something 10 times is unPythonic. The reason I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.