Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-27-2010, 06:43 PM   #1
LQ Newbie
Registered: Jan 2010
Posts: 1

Rep: Reputation: 0
STD sort with g++ -O3 segmentation fault


I have program like this:

  vector<A *>::iterator it;
  for ( it=vec.begin() ; it != vec.end(); it++ )
    cout << *it << " ";
  cout << endl;
  sort(vec.begin(), vec.end(), CompF);
with 'gcc -g' it runs well, but with 'gcc -g -O3' (with -O2 too) it crash.

output is something like this:
0x826fff8 0x8270440 0x82720b8 0x8273d40 0x82796b8 0x8279808 0x82799b0
and gdb says
in CompF (a=0x8273d40, b=0x209) at file.cpp:123
Why it try to compare something at address 0x209 when this address is not in the vector?
Old 01-27-2010, 06:55 PM   #2
Senior Member
Registered: Jul 2005
Distribution: Slackware
Posts: 2,014

Rep: Reputation: 115Reputation: 115
Sounds kind of like memory corruption.. which means that the problem isn't here at all, it's just exposed here.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 10:34 AM
how to sort std::vector<double>? markhod Programming 4 10-12-2005 05:21 AM
Segmentation fault? JiggaJerry Fedora 10 01-16-2005 05:01 PM
C++, using custom function to sort an std::list R00ts Programming 3 01-03-2005 10:41 AM
What is segmentation fault? koyi Programming 3 08-30-2003 01:03 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:10 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration