LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

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


Hello,

I have program like this:

Code:
  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:
Code:
0x826fff8 0x8270440 0x82720b8 0x8273d40 0x82796b8 0x8279808 0x82799b0
and gdb says
Code:
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, 05:55 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

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.
 
  


Reply



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 09:34 AM
how to sort std::vector<double>? markhod Programming 4 10-12-2005 04:21 AM
Segmentation fault? JiggaJerry Fedora 10 01-16-2005 04:01 PM
C++, using custom function to sort an std::list R00ts Programming 3 01-03-2005 09:41 AM
What is segmentation fault? koyi Programming 3 08-30-2003 12:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:27 AM.

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