View Single Post
Old Feb 10th, 2008, 10:33 AM   #4
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4 Jessehk is on a distinguished road
Re: Code Segfaults when compiled with optimizations, doesn't in arbitrary situations

Just a bit of an update. It turns out that the fact that the code was working before was just a fluke.
It was just a lucky coincidence like before.

The real culprit was Boost.Foreach.
For some reason, something like this:
c++ Syntax (Toggle Plain Text)
  1. const char LETTERS[] = { 'A', 'B' };
  2.  
  3. BOOST_FOREACH( char letter, LETTERS ) {
  4. // ...
  5. }

was not iterating the correct number of times and that was the result of the segfault. I'm trying to figure out if it was a bug in my code (which ATM seems unlikely) or a bug with Boost.Foreach and arrays.

In any case, your suspicion that the code was falling off the end of an array was correct.
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote